打印功能

This commit is contained in:
jiangs 2025-07-23 14:19:57 +08:00
parent fae8a30821
commit 585ec7a47f
18 changed files with 442 additions and 8 deletions

View File

@ -51,11 +51,20 @@ public class RuoYiConfig {
*/ */
private static String interfaceUrl; private static String interfaceUrl;
/**
* 门诊条码打印机名称
*/
private static String mzPrintName;
public static String getInterfaceUrl() { public static String getInterfaceUrl() {
return interfaceUrl; return interfaceUrl;
} }
public static void setInterfaceUrl(String interfaceUrl) { public void setInterfaceUrl(String interfaceUrl) {
RuoYiConfig.interfaceUrl = interfaceUrl; RuoYiConfig.interfaceUrl = interfaceUrl;
} }
@ -63,7 +72,7 @@ public class RuoYiConfig {
return interfaceType; return interfaceType;
} }
public static void setInterfaceType(String interfaceType) { public void setInterfaceType(String interfaceType) {
RuoYiConfig.interfaceType = interfaceType; RuoYiConfig.interfaceType = interfaceType;
} }
@ -142,4 +151,12 @@ public class RuoYiConfig {
public static String getUploadPath() { public static String getUploadPath() {
return getProfile() + "/upload"; return getProfile() + "/upload";
} }
public static String getMzPrintName() {
return mzPrintName;
}
public void setMzPrintName(String mzPrintName) {
RuoYiConfig.mzPrintName = mzPrintName;
}
} }

View File

@ -16,6 +16,31 @@
<groupId>com.czlis</groupId> <groupId>com.czlis</groupId>
<artifactId>lis-common</artifactId> <artifactId>lis-common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.barbecue</groupId>
<artifactId>barbecue</artifactId>
<version>1.5-beta1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

View File

@ -1,4 +1,9 @@
package com.czlis.interfaceCommon.mapper; package com.czlis.interfaceCommon.mapper;
import com.czlis.common.core.domain.entity.LabReqdetail;
import java.util.List;
public interface LabReqdetailMapper { public interface LabReqdetailMapper {
List<LabReqdetail> getLabReqdetailList(String sqh);
} }

View File

@ -0,0 +1,20 @@
package com.czlis.interfaceCommon.pojo.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MZBarCodeParam {
private String sqh;
private String brxm;
private String brxb;
private String nl;
private String sfxmmc;
private String ksmc;
}

View File

@ -1,6 +1,7 @@
package com.czlis.interfaceCommon.utils; package com.czlis.interfaceCommon.utils;
import com.czlis.common.core.domain.entity.LabPat; import com.czlis.common.core.domain.entity.LabPat;
import com.czlis.common.core.domain.entity.LabReqdetail;
import com.czlis.common.core.domain.entity.LabReqmain; import com.czlis.common.core.domain.entity.LabReqmain;
import com.czlis.common.core.domain.entity.LabResult; import com.czlis.common.core.domain.entity.LabResult;
import com.czlis.interfaceCommon.mapper.*; import com.czlis.interfaceCommon.mapper.*;
@ -27,6 +28,8 @@ public class CommonUtil {
ComDictMapper comDictMapper; ComDictMapper comDictMapper;
@Autowired @Autowired
private LabResultMapper labResultMapper; private LabResultMapper labResultMapper;
@Autowired
LabReqdetailMapper labReqdetailMapper;
//====检验主表操作方法集合=== //====检验主表操作方法集合===
public LabPat getLabPatOne(Date jyrq, String yq, String ybh){ public LabPat getLabPatOne(Date jyrq, String yq, String ybh){
@ -88,5 +91,9 @@ public class CommonUtil {
return comOptMapper.getComOptValue(yq,xxdh); return comOptMapper.getComOptValue(yq,xxdh);
} }
public List<LabReqdetail> getLabReqdetailList(String sqh){
return labReqdetailMapper.getLabReqdetailList(sqh);
}
} }

View File

@ -0,0 +1,68 @@
package com.czlis.interfaceCommon.utils;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class LisUtil {
/**
* 生日格式为:yyyy-MM-dd
* 根据出生日期计算年龄
* @param birthday
* @return
*/
public static Map<String,String> getAgeFromBirthDay(String birthday){
Map<String,String> map = new HashMap<>();
int age = DateUtil.ageOfNow(birthday);
if(age > 0){
map.put("age",String.valueOf(age));
map.put("unit","岁");
}else if(age == 0){
//不足一年的
long between = DateUtil.between(DateUtil.parse(birthday, "yyyy-MM-dd"), DateUtil.parse(DateUtil.today(), "yyyy-MM-dd"), DateUnit.DAY,true);
if(between/30 > 0){
long month = between/30;
map.put("age",String.valueOf(month));
map.put("unit","月");
}else if( between/30 == 0){
//不足一月的
map.put("age",String.valueOf(between));
map.put("unit","天");
}else{
}
}else{
}
return map;
}
/**
* 根据年龄获取出生日期
* @param nl
* @return
*/
public static Date getBirthDayFromAge(int nl, String nldw){
Calendar cal = Calendar.getInstance();
cal.setTime(DateUtil.date());
switch (nldw){
case "岁":
cal.add(Calendar.YEAR,-nl);
case "月":
cal.add(Calendar.MONTH,-nl);
case "天":
cal.add(Calendar.DATE,-nl);
}
Date BirthDay = cal.getTime();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
String format = df.format(BirthDay);
return DateUtil.parse(format,"yyyy-MM-dd");
}
}

View File

@ -0,0 +1,127 @@
package com.czlis.interfaceCommon.utils;
import com.czlis.common.config.RuoYiConfig;
import com.czlis.interfaceCommon.pojo.entity.MZBarCodeParam;
import lombok.extern.slf4j.Slf4j;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.export.JRPrintServiceExporter;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimplePrintServiceExporterConfiguration;
import org.springframework.stereotype.Component;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JasperPrint;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.standard.MediaSizeName;
@Component
@Slf4j
public class ReportUtil {
public void printBarCode(MZBarCodeParam mzBarCodeParam) {
String jrxmlPath = RuoYiConfig.getProfile() + "\\barcode.jrxml";
String jasperPath = RuoYiConfig.getProfile() + "\\barcode.jasper";
// 获取类路径(resources 目录)
String property = System.getProperty("user.dir");
System.out.println("打印路径:"+property);
//String resourcesPath = property + "\\lis-" + File.separator + jasperPath;
//编译模板
try {
JasperCompileManager.compileReportToFile(jrxmlPath,jasperPath);
//构造数据
Map parameters = new HashMap();
parameters.put("barcode",mzBarCodeParam.getSqh());
parameters.put("line1",mzBarCodeParam.getBrxm() + " " + mzBarCodeParam.getBrxb() + " " + mzBarCodeParam.getNl());
parameters.put("line2",mzBarCodeParam.getSfxmmc());
//填充数据
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperPath, parameters, new JREmptyDataSource());
//输出文件
// String pdfPath = "E:\\barcode.pdf";
// JasperExportManager.exportReportToPdfFile(jasperPrint,pdfPath);
// printPdfFile(pdfPath);
//打印条码
//JasperPrintManager.printReport(jasperPrint, false);
print(jasperPrint,false, RuoYiConfig.getMzPrintName());
} catch (Exception e) {
e.printStackTrace();
log.error("打印条码报错,条码号:{}",mzBarCodeParam.getSqh(),e);
}
}
/**
* 6.8.0版本专用:指定打印机打印报表
* @param jasperPrint 报表对象
* @param showDialog 是否显示打印对话框
* @param printerName 目标打印机名称(支持模糊匹配)
* @throws Exception 打印异常
*/
public static void print(JasperPrint jasperPrint, boolean showDialog, String printerName) throws Exception {
// 1. 获取系统中所有可用打印机
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
if (printServices == null || printServices.length == 0) {
throw new RuntimeException("未检测到任何可用打印机");
}
// 2. 查找目标打印机(6.8.0版本兼容的遍历方式)
PrintService targetService = null;
for (PrintService service : printServices) {
String serviceName = service.getName();
// 精确匹配可改为:serviceName.equals(printerName)
if (serviceName.contains(printerName)) {
targetService = service;
break;
}
}
if (targetService == null) {
throw new RuntimeException("未找到名称包含 [" + printerName + "] 的打印机");
}
// 3. 配置打印参数(6.8.0版本的标准API)
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
SimplePrintServiceExporterConfiguration config = new SimplePrintServiceExporterConfiguration();
// 设置目标打印机
config.setPrintService(targetService);
// 控制是否显示系统打印对话框(6.8.0版本此参数有效)
config.setDisplayPrintDialog(showDialog);
// 不显示页面设置对话框(如需显示可改为true)
config.setDisplayPageDialog(false);
// 4. 设置打印属性(份数、纸张等)
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(new Copies(1)); // 打印份数
attributes.add(MediaSizeName.ISO_A4); // 纸张大小A4
// 可选:设置打印方向(横向)
// attributes.add(OrientationRequested.LANDSCAPE);
config.setPrintRequestAttributeSet(attributes);
// 5. 绑定报表并执行打印(6.8.0版本的标准导出方式)
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setConfiguration(config);
exporter.exportReport();
}
}

View File

@ -0,0 +1,2 @@
net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.lobstertwo=stsong/fonts.xml

View File

@ -0,0 +1,11 @@
<?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.LabReqdetailMapper">
<select id="getLabReqdetailList" resultType="com.czlis.common.core.domain.entity.LabReqdetail">
select * from lab_reqdetail where sqh = #{sqh}
</select>
</mapper>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="华文宋体">
<normal>stsong/stsong.ttf</normal>
<bold>stsong/stsong.ttf</bold>
<italic>stsong/stsong.ttf</italic>
<boldItalic>stsong/stsong.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'华文宋体',Arial,Helvetica,sans-serif</export>
<export key="net.sf.jasperreports.xhtml">'华文宋体',Arial,Helvetica,sans-serif</export>
</exportFonts>
</fontFamily>
</fontFamilies>

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.9.0.final using JasperReports Library version 6.9.0-cb8f9004be492ccc537180b49c026951f4220bf3 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="barcode" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="fbec7cd4-b278-4201-aae2-7cfd7e7b953c">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="barcode" class="java.lang.String"/>
<parameter name="line1" class="java.lang.String"/>
<parameter name="line2" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="184" splitType="Stretch">
<componentElement>
<reportElement x="6" y="6" width="130" height="32" uuid="e6aa5ef9-8f70-45cb-969e-8484f75390bb">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="Code128" drawText="false" checksumRequired="false">
<jr:codeExpression><![CDATA[$P{barcode}]]></jr:codeExpression>
</jr:barbecue>
</componentElement>
<textField>
<reportElement x="17" y="23" width="100" height="15" uuid="925826fe-f359-43dd-b4c2-aa5fee83be67"/>
<textElement>
<font fontName="华文宋体" size="10"/>
</textElement>
<textFieldExpression><![CDATA[$P{barcode}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="7" y="39" width="128" height="15" uuid="9029e1d0-5307-4d60-8098-225825491e85">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement>
<font fontName="华文宋体" size="10"/>
</textElement>
<textFieldExpression><![CDATA[$P{line1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="6" y="56" width="130" height="15" uuid="902afe45-cfe9-4095-9a76-b0ea517a08b3">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement>
<font fontName="华文宋体" size="10"/>
</textElement>
<textFieldExpression><![CDATA[$P{line2}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>

View File

@ -7,12 +7,12 @@ czlis:
# 版权年份 # 版权年份
copyrightYear: 2025 copyrightYear: 2025
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
profile: D:/czlis/uploadPath profile: D:/czlis/upload
mzPrintName: pdfFactory Pro
# 获取ip地址开关 # 获取ip地址开关
addressEnabled: false addressEnabled: false
# 验证码类型 math 数字计算 char 字符验证 # 验证码类型 math 数字计算 char 字符验证
captchaType: math captchaType: math
interfaceType: 1
interfaceUrl: http://localhost:8080 interfaceUrl: http://localhost:8080
# 开发环境配置 # 开发环境配置

View File

@ -34,7 +34,7 @@ public class MZCXController extends BaseController {
@ApiOperation("获取申请单信息") @ApiOperation("获取申请单信息")
@GetMapping("/querySQD") @GetMapping("/querySQD")
public Result querySQD(String brdh,String stime,String etime,String klx,String zt){ public Result querySQD(String brdh,String stime,String etime,String klx,String zt){
return mzcxService.querySQD(brdh,stime,etime,klx,zt); return mzcxService.querySQD(brdh,stime,etime,klx,zt,getUserId());
} }
/** /**
@ -44,6 +44,6 @@ public class MZCXController extends BaseController {
*/ */
@GetMapping("/printBarcode") @GetMapping("/printBarcode")
public Result printSQD(String sqh){ public Result printSQD(String sqh){
return null; return mzcxService.printSQD(sqh);
} }
} }

View File

@ -6,5 +6,7 @@ import com.czlis.mzcx.pojo.MzcxSqdDTO;
import java.util.List; import java.util.List;
public interface MZCXService { public interface MZCXService {
Result querySQD(String brdh, String stime, String etime, String klx, String zt); Result querySQD(String brdh, String stime, String etime, String klx, String zt,Long userId);
Result printSQD(String sqh);
} }

View File

@ -1,6 +1,17 @@
package com.czlis.mzcx.service.impl; package com.czlis.mzcx.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.czlis.common.core.domain.Result; 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.interfaceCommon.constants.LisinterfaceNameConstants;
import com.czlis.interfaceCommon.pojo.entity.MZBarCodeParam;
import com.czlis.interfaceCommon.pojo.inter.GetReqInterface;
import com.czlis.interfaceCommon.utils.CommonUtil;
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.mapper.MZCXMapper;
import com.czlis.mzcx.pojo.MzcxSqdDTO; import com.czlis.mzcx.pojo.MzcxSqdDTO;
import com.czlis.mzcx.service.MZCXService; import com.czlis.mzcx.service.MZCXService;
@ -8,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.validation.constraints.NotBlank;
import java.util.*; import java.util.*;
@Service @Service
@ -16,9 +28,27 @@ public class MZCXServiceImpl implements MZCXService {
@Autowired @Autowired
MZCXMapper mzcxMapper; MZCXMapper mzcxMapper;
@Autowired
ReportUtil reportUtil;
@Autowired
LisInterfaceUtil lisInterfaceUtil;
@Autowired
private CommonUtil commonUtil;
@Override @Override
public Result querySQD(String brdh, String stime, String etime, String klx,String zt) { public Result querySQD(String brdh, String stime, String etime, String klx,String zt,Long userId) {
GetReqInterface getReqInterface = new GetReqInterface();
getReqInterface.setBrdh(brdh);
getReqInterface.setStime(stime);
getReqInterface.setEtime(etime);
getReqInterface.setBrly("");
getReqInterface.setSqh("");
getReqInterface.setBz1("");
getReqInterface.setUserid(userId.toString());
getReqInterface.setYljg("1");
getReqInterface.setDept("");
String jsonStr = JSONUtil.toJsonStr(getReqInterface);
Result result = lisInterfaceUtil.invokeLisInterface(LisinterfaceNameConstants.GETREQINTERFACE, jsonStr);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("brdh", brdh); map.put("brdh", brdh);
map.put("st", stime); map.put("st", stime);
@ -29,6 +59,35 @@ public class MZCXServiceImpl implements MZCXService {
return new Result("0","修改条码成功!",mzcxMapper.querySQD(map)); return new Result("0","修改条码成功!",mzcxMapper.querySQD(map));
} }
@Override
public Result printSQD(String sqh) {
LabReqmain labReqmainOne = commonUtil.getLabReqmainOne(sqh);
//List<LabReqdetail> labReqdetailList = commonUtil.getLabReqdetailList(sqh);
MZBarCodeParam mzBarCodeParam = new MZBarCodeParam();
mzBarCodeParam.setSqh(sqh);
Map<String, String> ageFromBirthDay = LisUtil.getAgeFromBirthDay(DateUtil.format(labReqmainOne.getBrsr(), "yyyy-MM-dd HH:mm:ss"));
String age = ageFromBirthDay.get("age");
String unit = ageFromBirthDay.get("unit");
mzBarCodeParam.setNl(age+unit);
mzBarCodeParam.setBrxm(labReqmainOne.getBrxm());
String brxb = labReqmainOne.getBrxb();
switch (brxb){
case "1":
brxb = "男";
break;
case "2":
brxb = "女";
break;
default:
brxb = "";
}
mzBarCodeParam.setBrxb(brxb);
mzBarCodeParam.setSfxmmc(labReqmainOne.getJymd());
reportUtil.printBarCode(mzBarCodeParam);
return null;
}
} }

24
pom.xml
View File

@ -39,6 +39,9 @@
<knife4j.version>3.0.3</knife4j.version> <knife4j.version>3.0.3</knife4j.version>
<sqlserver.version>8.2.2.jre8</sqlserver.version> <sqlserver.version>8.2.2.jre8</sqlserver.version>
<pinyin4j.version>2.5.1</pinyin4j.version> <pinyin4j.version>2.5.1</pinyin4j.version>
<jasperreports.version>6.8.0</jasperreports.version>
<itext.version>2.1.7</itext.version>
<barbecue.version>1.5-beta1</barbecue.version>
<!-- override dependency version --> <!-- override dependency version -->
<tomcat.version>9.0.98</tomcat.version> <tomcat.version>9.0.98</tomcat.version>
@ -289,6 +292,27 @@
<artifactId>pinyin4j</artifactId> <artifactId>pinyin4j</artifactId>
<version>${pinyin4j.version}</version> <version>${pinyin4j.version}</version>
</dependency> </dependency>
<!-- 模版编辑器-->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>${itext.version}</version> <!-- 旧版稳定版本 -->
</dependency>
<dependency>
<groupId>net.sourceforge.barbecue</groupId>
<artifactId>barbecue</artifactId>
<version>${barbecue.version}</version>
</dependency>
</dependencies> </dependencies>