This commit is contained in:
tangw 2025-08-01 17:34:03 +08:00
parent bfc250f562
commit 7b01d9bd72
9 changed files with 351 additions and 142 deletions

View File

@ -0,0 +1,12 @@
package com.czlis.interfaceCommon.mapper;
import com.czlis.common.core.domain.entity.LabReqmain;
import com.czlis.interfaceCommon.pojo.entity.BackPaperDetail;
import com.czlis.interfaceCommon.pojo.entity.BackPaperParam;
import java.util.List;
public interface BackPaperMapper {
List<BackPaperDetail> selectBySqhs(List<String> sqhs);
BackPaperParam selectReqmian(String sqh);
}

View File

@ -0,0 +1,17 @@
package com.czlis.interfaceCommon.pojo.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BackPaperDetail {
private String sqh;
private Integer xh;
private String bz1;
private String sqxmdh;
private String sqxmmc;
private String cp_msg;
}

View File

@ -0,0 +1,36 @@
package com.czlis.interfaceCommon.pojo.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BackPaperParam {
private String ksdh;
private String sqys;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date sqsj;
private String jsys;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date jssj;
private String brly;
private String brdh;
private String brxm;
private String brxb;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date brsr;
private String txm;
private String bgddh;
private Integer nl;
private String nldw;
private String kh;
private String yljg;
}

View File

@ -11,6 +11,8 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Component
@ -68,6 +70,24 @@ public class CommonUtil {
public Date getCurrentTime(){return commonMapper.getCurrentTime();}
public String getCurrentDate(){return DateFormatUtils.format(commonMapper.getCurrentTime(), "yyyy-MM-dd");}
public String getCurrentDateTime(){return DateFormatUtils.format(commonMapper.getCurrentTime(), "yyyy-MM-dd HH:mm:ss");}
//字典查询单位名称
public String getCompany(String yljg){
if(yljg == null || yljg.equals(""))return getCompany();
String zdmc=getComDictNameById("HOS",yljg);
if(zdmc == null || zdmc.equals("")){
return yljg;
}else{
return zdmc;
}
}
public String getCompany(){
String zdmc=getComDictNameById("99","COMPANY");
if(zdmc == null || zdmc.equals("")){
return "";
}else{
return zdmc;
}
}
//字典查询方法集合
public String getComDictNameById(String zdlb,String xxdh){
@ -96,4 +116,5 @@ public class CommonUtil {
}
}

View File

@ -1,5 +1,6 @@
package com.czlis.interfaceCommon.utils;
import com.czlis.common.config.RuoYiConfig;
import lombok.extern.slf4j.Slf4j;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
@ -10,12 +11,12 @@ import net.sf.jasperreports.engine.util.JRSaver;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
import net.sf.jasperreports.export.SimplePrintServiceExporterConfiguration;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.io.FileInputStream;
import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -36,13 +37,11 @@ import javax.print.attribute.standard.OrientationRequested;
@Component
@Slf4j
public class JasperReportUtil {
private static final String template="template";
private static final String templatep="template/";
private static final String TEMPLATE_PATH = JasperReportUtil.getTemplatePath();
/**
* 核心打印/导出方法
* @param printerName 打印机名称(可为null,null时使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在resources/template目录下)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param parameters 非循环字段集合(报表参数,如标题、日期等)
* @param dataList 循环体数据(List集合,每条数据对应detail区域一行)
* @param pdfType 打印方式(pdfType为true导出PDF)
@ -51,6 +50,7 @@ public class JasperReportUtil {
* @param papersize 纸张尺寸(可为null,默认使用模板纸张)
* @param Orientation 纸张方向(false直打,true横打)
* @param showDialog 打印前是否预览(false直接打印,true预览)
* @param connection 数据源,推荐使用DataSource注入对象传递当前库连接对象
* @throws Exception Jasper相关异常
*/
public static void printbase(
@ -63,14 +63,21 @@ public class JasperReportUtil {
Integer printtimes,
String papersize,
boolean Orientation,
boolean showDialog
boolean showDialog,
Connection connection
) throws Exception {
// 1. 校验入参
// validateParams(printType, exportPath, dataList);
// 1. 在 printbase 中获取配置路径并初始化目录
String templateDir = getTemplateDir(); // 获取配置路径
String templatePath = templateDir + File.separator;
initTemplateDir(templateDir); // 初始化目录(不存在则创建)
// 在 printbase 方法开头添加
if (pdfType && (exportPath == null || exportPath.trim().isEmpty())) {
throw new IllegalArgumentException("导出PDF时,exportPath不能为空");
}
// 2. 加载并编译模板(支持jrxml和jasper)
JasperReport jasperReport;
try {
jasperReport = loadTemplate(templateName);
jasperReport = loadTemplate(templateName,templatePath);
} catch (Exception e) {
log.error("打印模板创建错误:{}",e);
throw new RuntimeException(e);
@ -84,8 +91,12 @@ public class JasperReportUtil {
}
// 4. 填充报表(参数+循环数据)
Map<String, Object> safeParams = parameters != null ? parameters : new HashMap<>();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, safeParams, dataSource);
JasperPrint jasperPrint=null;
if (connection != null) {
jasperPrint = JasperFillManager.fillReport(jasperReport, safeParams,connection);
}else {
jasperPrint = JasperFillManager.fillReport(jasperReport, safeParams, dataSource);
}
// 5. 根据打印方式执行操作
if (pdfType==false) {
// 5.1 直接打印到指定打印机
@ -95,38 +106,47 @@ public class JasperReportUtil {
exportToPdf(jasperPrint, exportPath);
}
}
/**
* 加载并编译模板(优先加载jasper,不存在则编译jrxml)
*/
private static JasperReport loadTemplate(String templateName) throws Exception {
// 模板路径:resources/templates/
String templatePath = templatep + templateName;
compileAndSave(templateName);
InputStream jasperStream = JasperReportUtil.class.getClassLoader().getResourceAsStream(templatePath + ".jasper");
if (jasperStream != null) {
// 存在已编译的jasper文件,直接加载
return (JasperReport) JRLoader.loadObject(jasperStream);
} else {
// 不存在jasper,编译jrxml
InputStream jrxmlStream = JasperReportUtil.class.getClassLoader().getResourceAsStream(templatePath + ".jrxml");
if (jrxmlStream == null) {
throw new JRException("模板不存在:" + templatePath + ".jrxml/.jasper");
}
return JasperCompileManager.compileReport(jrxmlStream);
/**
* 加载并编译模板(从物理路径 D:\template 加载)
*/
private static JasperReport loadTemplate(String templateName,String templatePath) throws Exception {
// 物理路径模板文件(支持 jrxml 和 jasper)
String jrxmlPath = templatePath + templateName + ".jrxml";
String jasperPath = templatePath + templateName + ".jasper";
compileAndSave(templateName,templatePath);
// 1. 优先加载已编译的 jasper 文件
File jasperFile = new File(jasperPath);
if (jasperFile.exists() && jasperFile.isFile()) {
try (FileInputStream fis = new FileInputStream(jasperFile)) {
return (JasperReport) JRLoader.loadObject(fis);
}
}
// 2. 无 jasper 文件则编译 jrxml
File jrxmlFile = new File(jrxmlPath);
if (!jrxmlFile.exists() || !jrxmlFile.isFile()) {
throw new JRException("模板文件不存在:" + jrxmlPath);
}
try (FileInputStream fis = new FileInputStream(jrxmlFile)) {
return JasperCompileManager.compileReport(fis);
}
}
/**
* 直接打印到指定打印机
*/
private static void printToPrinter(JasperPrint jasperPrint, String printerName,Integer printtimes,String papersize,boolean Orientation,boolean showDialog) throws JRException {
private static void printToPrinter(JasperPrint jasperPrint, String printerName,Integer printtimes,String papersize,boolean isLandscape,boolean showDialog) throws JRException {
// 查找目标打印机
PrintService printService = findPrintService(printerName);
if (printService == null) {
throw new JRException("未找到指定打印机:" + (printerName == null ? "默认打印机" : printerName));
}
if (printtimes != null && printtimes <= 0) {
throw new IllegalArgumentException("打印次数必须为正整数(printtimes=" + printtimes + ")");
}
// 配置打印参数(跳过打印对话框,直接打印)
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
SimplePrintServiceExporterConfiguration config = new SimplePrintServiceExporterConfiguration();
@ -146,7 +166,7 @@ public class JasperReportUtil {
}
}
// 可选:设置打印方向(横向)
if(Orientation)attributes.add(OrientationRequested.LANDSCAPE);
if(isLandscape)attributes.add(OrientationRequested.LANDSCAPE);
config.setPrintRequestAttributeSet(attributes);
// 执行打印
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
@ -158,6 +178,12 @@ public class JasperReportUtil {
* 导出为PDF文件
*/
private static void exportToPdf(JasperPrint jasperPrint, String exportPath) throws JRException {
// exportToPdf 方法中添加
File exportFile = new File(exportPath);
File parentDir = exportFile.getParentFile();
if (parentDir != null && !parentDir.exists()) {
parentDir.mkdirs(); // 创建父目录
}
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(exportPath));
@ -171,7 +197,7 @@ public class JasperReportUtil {
// 获取所有可用打印机
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
if (printServices == null || printServices.length == 0) {
return null;
return PrintServiceLookup.lookupDefaultPrintService(); // 替代 return null
}
// 1. 打印机名称为null时,返回默认打印机
@ -185,7 +211,8 @@ public class JasperReportUtil {
return service;
}
}
return null;
// findPrintService 方法末尾修改
return PrintServiceLookup.lookupDefaultPrintService(); // 替代 return null
}
// ------------------------------ 简化调用的重载方法(可选)------------------------------
@ -198,13 +225,53 @@ public class JasperReportUtil {
List<?> dataList,
String exportPath
) throws Exception {
printbase(null, templateName, parameters, dataList, true, exportPath,null,null,false,false);
printbase(null, templateName, parameters, dataList, true, exportPath,null,null,false,false,null);
}
public static void exportToPdf(
String templateName,
Map<String, Object> parameters,
Connection connection,
String exportPath
) throws Exception {
printbase(null, templateName, parameters,null, true, exportPath,null,null,false,false,connection);
}
/**
* 重载:直接打印(简化参数)
* @param printerName 打印机名称(可为null,null时使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param parameters 非循环字段集合(报表参数,如标题、日期等)
* @param dataList 循环体数据(List集合,每条数据对应detail区域一行)
* @param connection 数据源,推荐使用DataSource注入对象传递当前库连接对象
*/
public static void print(
String printerName,
String templateName,
Map<String, Object> parameters,
List<?> dataList,
Connection connection
) throws Exception {
printbase(printerName, templateName, parameters, dataList, false, null,null,null,false,false,connection);
}
/**
* 重载:直接打印(简化参数)
* @param printerName 打印机名称(可为null,null时使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param parameters 非循环字段集合(报表参数,如标题、日期等)
* @param connection 数据源,推荐使用DataSource注入对象传递当前库连接对象
*/
public static void print(
String printerName,
String templateName,
Map<String, Object> parameters,
Connection connection
) throws Exception {
printbase(printerName, templateName, parameters, null, false, null,null,null,false,false,connection);
}
/**
* 重载:直接打印(简化参数)
* @param printerName 打印机名称(可为null,null时使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在resources/template目录下)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param parameters 非循环字段集合(报表参数,如标题、日期等)
* @param dataList 循环体数据(List集合,每条数据对应detail区域一行)
*/
@ -214,12 +281,12 @@ public class JasperReportUtil {
Map<String, Object> parameters,
List<?> dataList
) throws Exception {
printbase(printerName, templateName, parameters, dataList, false, null,null,null,false,false);
printbase(printerName, templateName, parameters, dataList, false, null,null,null,false,false,null);
}
/**
* 重载:直接打印(简化参数)
* @param printerName 打印机名称(可为null,null时使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在resources/template目录下)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param dataList 循环体数据(List集合,每条数据对应detail区域一行)
*/
public static void print(
@ -232,7 +299,20 @@ public class JasperReportUtil {
/**
* 重载:直接打印(简化参数)
* @param printerName 打印机名称(可为null,null时使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在resources/template目录下)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param connection 数据源,推荐使用DataSource注入对象传递当前库连接对象
*/
public static void print(
String printerName,
String templateName,
Connection connection
) throws Exception {
print(printerName, templateName, null, connection);
}
/**
* 重载:直接打印(简化参数)
* @param printerName 打印机名称(可为null,null时使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param parameters 非循环字段集合(报表参数,如标题、日期等)
*/
public static void print(
@ -240,22 +320,38 @@ public class JasperReportUtil {
String templateName,
Map<String, Object> parameters
) throws Exception {
print(printerName, templateName, parameters, null);
List<?> dataList =null;
print(printerName, templateName, parameters, dataList );
}
/**
* 重载:直接打印(使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在resources/template目录下)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param parameters 非循环字段集合(报表参数,如标题、日期等)
* @param connection 数据源,推荐使用DataSource注入对象传递当前库连接对象
*/
public static void print(
String templateName,
Map<String, Object> parameters,
Connection connection
) throws Exception {
List<?> dataList =null;
print(null, templateName, parameters, dataList,connection);
}
/**
* 重载:直接打印(使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param parameters 非循环字段集合(报表参数,如标题、日期等)
*/
public static void print(
String templateName,
Map<String, Object> parameters
) throws Exception {
print(null, templateName, parameters, null);
List<?> dataList =null;
print(null, templateName, parameters, dataList);
}
/**
* 重载:直接打印(使用默认打印机)
* @param templateName 模板名称(支持jrxml或jasper,放在resources/template目录下)
* @param templateName 模板名称(支持jrxml或jasper,放在YML配置的物理路径下,如D:\ruoyi)
* @param dataList 循环体数据(List集合,每条数据对应detail区域一行)
*/
public static void print(
@ -274,6 +370,9 @@ public class JasperReportUtil {
SIZE_MAP.put("A4", MediaSizeName.ISO_A4);
SIZE_MAP.put("A5", MediaSizeName.ISO_A5);
SIZE_MAP.put("A6", MediaSizeName.ISO_A6);
SIZE_MAP.put("B5", MediaSizeName.ISO_B5);
SIZE_MAP.put("B4", MediaSizeName.ISO_B4);
SIZE_MAP.put("B6", MediaSizeName.ISO_B6);
// 可添加更多映射(如 US Letter、Legal 等)
}
public static MediaSizeName getMediaSize(String sizeStr) {
@ -285,102 +384,53 @@ public class JasperReportUtil {
* @param jrxmlFileName 模板文件名(不带扩展名,如"barcode")
* @throws Exception 编译或IO异常
*/
public static void compileAndSave(String jrxmlFileName) throws Exception {
// 1. 定义文件名和路径
String jrxmlName = jrxmlFileName + ".jrxml"; // jrxml文件名
String jasperName = jrxmlFileName + ".jasper"; // 编译后文件名
if(needCompile(TEMPLATE_PATH+jrxmlName, TEMPLATE_PATH+jasperName)) {
// 2. 获取resources/templates下的jrxml输入流
InputStream jrxmlStream = JasperReportUtil.class
.getClassLoader()
.getResourceAsStream(templatep + jrxmlName);
if (jrxmlStream == null) {
throw new Exception("未找到jrxml模板:" + templatep + jrxmlName);
}
// 3. 编译jrxml为JasperReport对象
JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlStream);
// 4. 确定输出目录(resources/templates的同级目录,即classes/templates)
File outputDir = getTemplateOutputDir();
if (!outputDir.exists()) {
outputDir.mkdirs(); // 目录不存在则创建
}
// 5. 输出jasper文件到目标目录
File jasperFile = new File(outputDir, jasperName);
JRSaver.saveObject(jasperReport, jasperFile); // 保存编译结果
System.out.println("编译成功:" + jasperFile.getAbsolutePath());
}
}
/**
* 获取模板输出目录(resources/templates编译后的目录)
* 编译 jrxml 并保存到物理模板目录(D:\template)
*/
private static File getTemplateOutputDir() throws URISyntaxException {
// 获取templates目录的URL(开发时是resources/templates,运行时是classes/templates)
URL templateUrl = JasperReportUtil.class.getClassLoader().getResource(template);
public static void compileAndSave(String jrxmlFileName,String templatePath) throws Exception {
String jrxmlPath = templatePath + jrxmlFileName + ".jrxml";
String jasperPath = templatePath + jrxmlFileName + ".jasper";
if (templateUrl == null) {
// 如果templates目录不存在,创建在classes目录下
URL classesUrl = JasperReportUtil.class.getClassLoader().getResource("");
return new File(classesUrl.toURI().getPath() + File.separator + template);
}
// 返回templates目录的File对象
return new File(templateUrl.toURI());
}
/**
* 检查是否需要编译jrxml(jrxml修改时间晚于jasper时需要编译)
* @param jrxmlPath jrxml文件路径(如"src/main/resources/templates/barcode.jrxml")
* @param jasperPath jasper文件路径(如"src/main/resources/templates/barcode.jasper")
* @return true:需要编译;false:无需编译
*/
public static boolean needCompile(String jrxmlPath, String jasperPath) {
// 1. 判断jasper文件是否存在:不存在则需要编译
File jasperFile = new File(jasperPath);
if (!jasperFile.exists()) {
log.info("jasper文件不存在,需要编译{}",jasperPath);
return true;
}
// 2. 判断jrxml文件是否存在
// 判断是否需要编译(jrxml 存在且比 jasper 新)
File jrxmlFile = new File(jrxmlPath);
if (!jrxmlFile.exists()) {
throw new IllegalArgumentException("jrxml文件不存在:" + jrxmlPath);
File jasperFile = new File(jasperPath);
// 仅当 jrxml 存在且比 jasper 新(或 jasper 不存在)时才编译
if (jrxmlFile.exists() && (!jasperFile.exists() || jrxmlFile.lastModified() > jasperFile.lastModified())) {
try (FileInputStream fis = new FileInputStream(jrxmlFile)) {
JasperReport jasperReport = JasperCompileManager.compileReport(fis);
JRSaver.saveObject(jasperReport, jasperFile);
log.info("jrxml 编译成功,保存至:{}", jasperPath);
}
}
}
// ------------------------------ 路径相关方法 ------------------------------
// 3. 比较修改时间:jrxml比jasper新 → 需要编译
long jrxmlTime = jrxmlFile.lastModified();
long jasperTime = jasperFile.lastModified();
boolean needCompile = jrxmlTime > jasperTime;
if (needCompile) {
log.info("jrxml已修改(" + jrxmlTime + "),晚于jasper(" + jasperTime + "),需要编译");
} else {
// log.info("jasper文件最新,无需编译");
}
return needCompile;
}
/**
* 获取 resources/templates/ 目录的绝对路径
* @return 目录路径(如 "D:/project/target/classes/templates/")
* 从配置中获取模板目录路径(在 printbase 中调用)
*/
public static String getTemplatePath() {
try {
// 通过类加载器获取 templates 目录的URL
URL templateUrl = JasperReportUtil.class.getClassLoader().getResource(template);
private static String getTemplateDir() {
String dir = RuoYiConfig.getProfile();
if (dir == null || dir.trim().isEmpty()) {
throw new IllegalStateException("配置文件中未设置有效的 profile 路径,请检查 application.yml");
}
return dir.trim();
}
// 如果URL为空,说明目录不存在,但仍返回理论路径
if (templateUrl == null) {
URL resourcesUrl = JasperReportUtil.class.getClassLoader().getResource("");
return resourcesUrl.toURI().getPath() + templatep;
/**
* 初始化模板目录(不存在则创建)
*/
private static void initTemplateDir(String templateDir) {
File dir = new File(templateDir);
if (!dir.exists()) {
boolean created = dir.mkdirs();
if (created) {
log.info("模板目录初始化成功:{}", templateDir);
} else {
log.error("模板目录创建失败,请检查路径权限:{}", templateDir);
}
}
}
// 返回实际路径
return templateUrl.toURI().getPath()+"/";
} catch (URISyntaxException e) {
throw new RuntimeException("获取路径失败", e);
}
}
}

View File

@ -1,13 +1,25 @@
package com.czlis.interfaceCommon.utils;
import com.czlis.common.config.RuoYiConfig;
import com.czlis.interfaceCommon.mapper.BackPaperMapper;
import com.czlis.interfaceCommon.pojo.entity.BackPaperDetail;
import com.czlis.interfaceCommon.pojo.entity.BackPaperParam;
import com.czlis.interfaceCommon.pojo.entity.MZBarCodeParam;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.sql.Connection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -15,7 +27,10 @@ import java.util.Map;
@Component
@Slf4j
public class ReportUtil {
@Autowired
CommonUtil commonUtil;
@Autowired
BackPaperMapper backPaperMapper;
public void printBarCode(MZBarCodeParam mzBarCodeParam) {
try {
//构造数据
@ -29,7 +44,50 @@ public class ReportUtil {
log.error("打印条码报错,条码号:{}",mzBarCodeParam.getSqh(),e);
}
}
public void printBackpaper(List<String> sqhs) {
String sqh= sqhs.get(0);
BackPaperParam backPaperParam=backPaperMapper.selectReqmian(sqh);
String yljg= backPaperParam.getYljg();
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> parameters = objectMapper.convertValue(backPaperParam,Map.class);
parameters.put("company",commonUtil.getCompany(yljg));
List<BackPaperDetail> detail= backPaperMapper.selectBySqhs(sqhs);
try {
//构造数据
JasperReportUtil.print(RuoYiConfig.getMzPrintName(),"backpaper",parameters,detail);
} catch (Exception e) {
e.printStackTrace();
log.error("打印回单报错,条码号:{}",sqh,e);
}
}
/*** 获取服务器当前的数据库连接事务对象
* 通过@Qualifier获取实际当前连接事务对象,一般是DynamicDataSource
* 传递服务器获取连接(使用 Spring 工具类确保连接与事务同步)
*/
/*
@Autowired
@Qualifier("dataSource")
private DataSource dataSource;
public void fillReportWithConnection() {
Connection connection = null;
try {
// 从数据源获取连接(自动关联当前事务,避免手动管理事务问题)
connection = DataSourceUtils.getConnection(dataSource);
// 3. 调用 JasperFillManager.fillReport
// InputStream reportStream = ...; // 模板输入流
// Map<String, Object> params = ...; // 报表参数
// JasperPrint jasperPrint = JasperFillManager.fillReport(reportStream, params, connection);
} catch (Exception e) {
log.error("填充报表失败", e);
} finally {
// 4. 释放连接(Spring 环境下需用 DataSourceUtils 关闭,避免事务问题)
if (connection != null) {
DataSourceUtils.releaseConnection(connection, dataSource);
}
}
}*/
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.czlis.interfaceCommon.mapper.BackPaperMapper">
<!-- 根据申请号集合查询 -->
<select id="selectBySqhs" resultType="com.czlis.common.core.domain.entity.LabReqdetail">
SELECT sqh,xh,sqxmdh,sqxmmc,'' as cp_msg FROM lab_reqdetail
WHERE sqh IN
<foreach collection="list" item="sqh" open="(" separator="," close=")">
#{sqh}
</foreach>
</select>
<select id="selectReqmian" resultType="com.czlis.mzcx.pojo.MzcxSqdDTO">
select * from lab_reqmain where sqh = #{sqh}
</select>
</mapper>

View File

@ -1,11 +1,9 @@
package com.czlis.mzcx.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.XmlUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.czlis.common.core.domain.Result;
import com.czlis.common.core.domain.entity.LabReqdetail;
import com.czlis.common.core.domain.entity.LabReqmain;
import com.czlis.common.utils.SecurityUtils;
import com.czlis.common.utils.ip.IpUtils;
@ -18,16 +16,12 @@ import com.czlis.interfaceCommon.utils.LisInterfaceUtil;
import com.czlis.interfaceCommon.utils.LisUtil;
import com.czlis.interfaceCommon.utils.ReportUtil;
import com.czlis.mzcx.mapper.MZCXMapper;
import com.czlis.mzcx.pojo.MzcxSqdDTO;
import com.czlis.mzcx.pojo.OutPatListDTO;
import com.czlis.mzcx.service.MZCXService;
import lombok.extern.slf4j.Slf4j;
import nonapi.io.github.classgraph.json.JSONUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.validation.constraints.NotBlank;
import java.util.*;
@Service
@ -131,6 +125,7 @@ public class MZCXServiceImpl implements MZCXService {
@Override
public Result printBackpaper(List<String> sqhs){
log.info("aaaaa: {}", sqhs);
reportUtil.printBackpaper(sqhs);
return new Result("0","打印成功!");
}

View File

@ -62,6 +62,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(lab_reqmain.sqsj <= #{et} )
]]>
</select>
<select id="querySQD1" resultType="com.czlis.mzcx.pojo.MzcxSqdDTO">
<![CDATA[
SELECT