检验报告单打印一直是个难点问题,JRT开发时候重点考虑了简化检验报告打印,首先采用脚本化方便快速修改报告。然后打印基础解决难点问题,基于JRT打印就可以简化到本文代码的水平,维护方便,结构清晰,上线修改方便。
打印实现
/*
本代码权归属于JRT计划,任何单位或个人未经许可,不得以任何方式复制、传播、展示、发布、分发、重新分发、修改、反编译、
反向编译或以其他方式使用本框架的任何部分,包括但不限于源代码、二进制文件、文档、演示文稿、示例代码和API。
使用本框架的用户需遵守以下条款:
用户只能以个人学习和研究为目的使用本框架,不得将其用于商业用途。
用户在使用本框架时,应遵守所有适用的法律和法规,包括但不限于版权法、商标法、专利法和隐私权法。
用户在使用本框架时,应自行承担风险和责任,并确保不会侵犯任何知识产权或个人权利。
本框架的使用仅限于用户自己使用,不得将其分发给其他用户或将其用于任何形式的共享或传播。
在使用本框架时,用户应尊重和保护其他用户的隐私和个人信息,不得将其泄露给任何第三方。
违反以上条款将视为侵权行为,将采取法律手段维护JRT合法权益。
*/
import JRT.Core.DataGrid.*;
import JRT.Core.Dto.HashParam;
import JRT.Core.Dto.OutValue;
import JRT.Core.Dto.PrintElement;
import JRT.Core.Util.Convert;
import JRT.Core.Util.LogUtils;
import JRT.Core.Util.PrintDrawProtocol;
import JRT.Model.Bussiness.Parameters;
import JRT.Model.Entity.*;
import JRTBLLBase.BaseHttpHandlerNoSession;
import JRTBLLBase.Helper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
/**
* 实现jrt检验报告的打印逻辑,包含检验报告和微生物报告
*/
public class LISPrintReport extends BaseHttpHandlerNoSession implements IGridChangePage {
/**
* 打印元素
*/
private List<PrintElement> retList = new ArrayList<>();
/**
* 打印模板数据
*/
JRTPrintTemplateDto template = null;
/**
* 存打印的Data数据
*/
Hashtable<String, String> printDataMap = null;
/**
* 水印字符串
*/
private String waterMark="";
/**
* 表格换页之前要执行的逻辑
*
* @param gridKey
* @param maxY
*/
public void PreChangePageDo(String gridKey, int maxY) {
}
/**
* 表格换页之后要执行的逻辑
*
* @param gridKey
* @param maxY
*/
public void AfterChangePageDo(String gridKey, int maxY) {
System.out.println("换页后执行逻辑");
//打印水印
PrintWaterMark(template, retList);
//画固定图片元素
PrintFixImage(template, retList);
//画数据元素
PrintData(template, retList, printDataMap);
//画标签元素
PrintLabel(template, retList);
//画线元素
PrintLine(template, retList);
}
/**
* 按传入的ReportDRS输出符合打印元素绘制协议的数据来实现打印控制,多个报告用上尖号分割
*
* @param Param 参数
* @param Session
* @param Output
* @return
*/
public String QueryPrintData(Parameters Param, OutValue Session, OutValue Output) throws Exception {
String ReportDRS = Param.P0;
String[] repArr = ReportDRS.split("\\^");
//循环打印每个报告
for (String repStr : repArr) {
if (Helper.IsEmptyStr(repStr)) {
continue;
}
long reportDR = Convert.ToLong(repStr);
RPVisitNumberReport rep=EntityManager().DolerGet(RPVisitNumberReport.class,reportDR);
RPVisitNumber vis=EntityManager().DolerGet(RPVisitNumber.class,rep.VisitNumberDR);
BTHospital hos=EntityManager().DolerGet(BTHospital.class,vis.HospitalDR);
waterMark=hos.CName+" "+Helper.GetNowDateStr()+" "+Helper.GetNowTimeStr();
//模板和打印关系的映射(报告与模板的关联)
HashMap<Long,List<RPVisitNumberReportResult>> templateMap=GetPrintTemplateMap(reportDR);
//处理大于关联,小于关联和代码关联(模板内部的关联)
templateMap=GetPrintTemplateInnerMap(templateMap,reportDR);
//循环打印每个模板的数据
for (Long tempDR : templateMap.keySet()) {
//查询模板数据
template = GetOneTemplate(tempDR, "");
//换报告之后无脑输出一个分页
retList.add(PrintDrawProtocol.ChangePage());
//查询并且填充Data
MakePrintDataMap(reportDR);
//存打印的图数据
HashMap<String, String> imgData = MakePrintImageData(reportDR);
//当前模板打印的报告项目
List<RPVisitNumberReportResult> templatePrintRes=templateMap.get(tempDR);
//查询结果数据
List<Object> repResList = MakePrintResultData(reportDR,templatePrintRes);
//打印水印
PrintWaterMark(template, retList);
//画固定图片元素
PrintFixImage(template, retList);
//画数据元素
PrintData(template, retList, printDataMap);
//画标签元素
PrintLabel(template, retList);
//画线元素
PrintLine(template, retList);
//画表格元素
PrintDataGrid(template, retList, repResList);
//打印报告图片
PrintReportImage(template, retList, imgData);
}
}
return Helper.Object2Json(retList);
}
/**
* 得到关联的模板,第一轮关联处理,得到每个模板打印哪些项目结果
* @param reportDR 报告主键
* @return
* @throws Exception
*/
private HashMap<Long,List<RPVisitNumberReportResult>> GetPrintTemplateMap(long reportDR) throws Exception
{
Long linkTempLateDR=null;
RPVisitNumberReport rep=EntityManager().DolerGet(RPVisitNumberReport.class,reportDR);
RPVisitNumber vis=EntityManager().DolerGet(RPVisitNumber.class,rep.VisitNumberDR);
//存模板打印的项目结果
List<RPVisitNumberReportResult> printReport=new ArrayList<>();
//存模板和打印结果的映射
HashMap<Long,List<RPVisitNumberReportResult>> printReportMap=new HashMap<>();
//得到医院下的所有关联数据
List<PTReportPrintLink> linkList=EntityManager().FindByColVal(PTReportPrintLink.class,"HospitalDR",vis.ReceiveHospitalDR);
HashMap<String,Long> linkMap=new HashMap<>();
if(linkList!=null&&linkList.size()>0)
{
for(PTReportPrintLink link:linkList)
{
if(link.WorkGroupMachineDR!=null)
{
linkMap.put("WGM-"+link.WorkGroupMachineDR,link.PrintTemplateDR);
}
if(link.TestSetDR!=null)
{
linkMap.put("TS-"+link.TestSetDR,link.PrintTemplateDR);
}
if(link.TestCodeDR!=null)
{
linkMap.put("TC-"+link.TestCodeDR,link.PrintTemplateDR);
}
if(link.TransTestCodeDR!=null)
{
linkMap.put("TRANSTC-"+Helper.ToStr(link.TransRes)+"-"+link.TransTestCodeDR,link.PrintTemplateDR);
}
}
}
//取工作小组关联
if(linkMap.containsKey("WGM-"+rep.WorkGroupMachineDR))
{
linkTempLateDR=linkMap.get("WGM-"+rep.WorkGroupMachineDR);
}
//得到主报告
long testSetReportDR=reportDR;
if (rep.SplitStatus.equals("M")) {
HashParam hs = new HashParam();
hs.Add("LinkReportDR", rep);
List<IDPResult> list = EntityManager().FindAllSimple(IDPResult.class, hs, "", 1, null, null);
if(list!=null&&list.size()>0) {
IDPResult idp = list.get(0);
testSetReportDR = idp.VisitNumberReportDR;
}
}
//按主报告取医嘱
HashParam hs=new HashParam();
hs.Add("VisitNumberReportDR",testSetReportDR);
List<RPVisitNumberTestSet> visTestSetList=EntityManager().FindAllSimple(RPVisitNumberTestSet.class,hs);
if(visTestSetList!=null&&visTestSetList.size()>0)
{
for(RPVisitNumberTestSet vists:visTestSetList)
{
//取医嘱关联
if(linkMap.containsKey("TS-"+vists.TestSetDR))
{
linkTempLateDR=linkMap.get("TS-"+vists.TestSetDR);
}
}
}
List<RPVisitNumberReportResult> resList = EntityManager().FindByColVal(RPVisitNumberReportResult.class, "VisitNumberReportDR", reportDR);
if (resList != null && resList.size() > 0) {
for (RPVisitNumberReportResult res : resList) {
if (res.IsNotAllowPrint != null && res.IsNotAllowPrint == true) {
continue;
}
if (Helper.IsEmptyStr(res.TextRes)) {
continue;
}
//取项目关联,项目用单独模板打印
if(linkMap.containsKey("TC-"+res.TestCodeDR))
{
long tempLateDR=linkMap.get("TC-"+res.TestCodeDR);
if(!printReportMap.containsKey(tempLateDR))
{
printReportMap.put(tempLateDR,new ArrayList<>());
}
List<RPVisitNumberReportResult> list=printReportMap.get(tempLateDR);
list.add(res);
}
else
{
printReport.add(res);
}
//取项目关联转移
if(linkMap.containsKey("TRANSTC-"+""+"-"+res.TestCodeDR))
{
linkTempLateDR=linkMap.get("TRANSTC-"+""+"-"+res.TestCodeDR);
}
//取项目关联转移
if(linkMap.containsKey("TRANSTC-"+res.TextRes+"-"+res.TestCodeDR))
{
linkTempLateDR=linkMap.get("TRANSTC-"+res.TextRes+"-"+res.TestCodeDR);
}
}
}
if(linkTempLateDR!=null)
{
printReportMap.put(linkTempLateDR,printReport);
}
return printReportMap;
}
/**
* 得到处理模板内部关联的映射,处理大于关联,小于关联,代码关联
* @param map
* @param reportDR
* @return
* @throws Exception
*/
private HashMap<Long,List<RPVisitNumberReportResult>> GetPrintTemplateInnerMap(HashMap<Long,List<RPVisitNumberReportResult>> map,long reportDR) throws Exception
{
HashMap<Long,List<RPVisitNumberReportResult>> ret=new HashMap<>();
for (Long key : map.keySet()) {
JRTPrintTemplate temp=EntityManager().DolerGet(JRTPrintTemplate.class,key);
List<RPVisitNumberReportResult> resList=map.get(key);
//优先用代码关联
if(Helper.IsNotEmptyStr(temp.CodeDef))
{
String [] arr=temp.CodeDef.split("\\^");
if(arr.length!=2)
{
throw new Exception("代码自由关联维护不符合约定,类名^方法名");
}
long tempDR=(long)Helper.GetBllMethodData(arr[0],arr[1],reportDR,key);
ret.put(tempDR,resList);
}
else if(temp.LargeNum!=null&&resList.size()>temp.LargeNum)
{
ret.put(temp.LargeTemplateDR,resList);
}
else if(temp.LeterNum!=null&&resList.size()<temp.LeterNum)
{
ret.put(temp.LeterTemplateDR,resList);
}
else
{
ret.put(key,resList);
}
}
return ret;
}
/**
* 构造打印的报告结果数据
*
* @param reportDR 报告主键
* @param resList 报告结果
* @return
*/
private List<Object> MakePrintResultData(long reportDR,List<RPVisitNumberReportResult> resList) throws Exception {
List<Object> retList = new ArrayList<>();
if (resList != null && resList.size() > 0) {
for (RPVisitNumberReportResult res : resList) {
if (res.IsNotAllowPrint != null && res.IsNotAllowPrint == true) {
continue;
}
if (Helper.IsEmptyStr(res.TextRes)) {
continue;
}
BTTestCode tsDto = EntityManager().DolerGet(BTTestCode.class, res.TestCodeDR);
HashMap out = new HashMap();
out.put("序号", retList.size() + 1);
out.put("项目名称", tsDto.CName);
out.put("缩写", tsDto.Synonym);
out.put("结果", res.TextRes);
out.put("标志", TransAbFlag(res.AbFlag));
out.put("单位", res.Unit);
out.put("参考范围", res.RefRanges);
out.put("实验方法", EntityManager().DolerGetCName(BTTestMethod.class, res.MethodDR));
out.put("多耐药", res.MultipleResChild);
if (tsDto.ResultFormat.equals("M")) {
out.put("菌落计数", res.Unit);
out.put("单位", "");
} else {
out.put("菌落计数", "");
}
out.put("专家规则", res.ExpertRule);
out.put("备注", res.ResNoes);
out.put("耐药机制", "");
//微生物取药敏结果
if (tsDto.ResultFormat.equals("M")) {
//查询药敏书记
List<RPVisitNumberReportResSen> senList = EntityManager().FindByColVal(RPVisitNumberReportResSen.class, "VisitNumberReportResultDR", res.RowID);
if (senList != null && senList.size() > 0) {
List<HashMap> senOutList = new ArrayList<>();
for (RPVisitNumberReportResSen sen : senList) {
BTAntibiotics ant = EntityManager().DolerGet(BTAntibiotics.class, sen.AntibioticsDR);
HashMap outSen = new HashMap();
outSen.put("序号", senOutList.size() + 1);
outSen.put("抗生素名称", ant.CName);
outSen.put("KB", Helper.ToStr(sen.KbValue));
outSen.put("MIC", Helper.ToStr(sen.MicValue));
outSen.put("ET", Helper.ToStr(sen.EtestValue));
outSen.put("敏感度", EntityManager().DolerGetCName(BTSensitivity.class, sen.SensitivityDR));
outSen.put("折点S", sen.SRanges);
outSen.put("折点I", sen.IRanges);
outSen.put("折点R", sen.RRanges);
outSen.put("折点SDD", sen.SDDRanges);
senOutList.add(outSen);
}
out.put("AntSen", senOutList);
}
//查询耐药机制书记
List<RPVisitNumberRepResRst> rstList=EntityManager().FindByColVal(RPVisitNumberRepResRst.class, "VisitNumberReportResultDR", res.RowID);
if(rstList!=null&&rstList.size()>0)
{
String rstStr="";
for(RPVisitNumberRepResRst rst:rstList)
{
if(Helper.IsEmptyStr(rst.TextResult))
{
continue;
}
BTMCResistanceItem rstItem=EntityManager().DolerGet(BTMCResistanceItem.class,rst.ResistanceItemDR);
rstStr+=rstItem.CName+":"+rst.TextResult+" ";
}
out.put("耐药机制", rstStr);
}
}
retList.add(out);
}
}
return retList;
}
/**
* 往打印单个数据里面塞入数据
*
* @param reportDR 报告主键
*/
private void MakePrintDataMap(long reportDR) throws Exception {
RPVisitNumberReport rep = EntityManager().DolerGet(RPVisitNumberReport.class, reportDR);
RPVisitNumberReportExt repExt = EntityManager().DolerGet(RPVisitNumberReportExt.class, rep.VisitNumberReportExtID);
RPVisitNumber vis = EntityManager().DolerGet(RPVisitNumber.class, rep.VisitNumberDR);
RPVisitNumberExt visExt = EntityManager().DolerGet(RPVisitNumberExt.class, vis.VisitNumberExtID);
//存打印的Data数据
printDataMap = new Hashtable<>();
printDataMap.put("姓名", vis.SurName);
printDataMap.put("性别", EntityManager().DolerGetCName(BTSpecies.class, vis.SpeciesDR));
printDataMap.put("年龄", vis.AgeDesc);
printDataMap.put("登记号", vis.RegNo);
printDataMap.put("检验号", vis.VisitNumber);
printDataMap.put("科室", EntityManager().DolerGetCName(BTLocation.class, vis.LocationDR));
printDataMap.put("标本", Helper.ToStr(EntityManager().DolerGetCol(BTSpecimen.class, vis.SpecimenDR, "IName")));
printDataMap.put("床号", vis.BedNo);
printDataMap.put("诊断", Helper.ToStr(visExt.Symptom));
printDataMap.put("采集日期", Helper.DateIntToStr(vis.CollectDate));
printDataMap.put("采集时间", Helper.TimeIntToStr(vis.CollectTime));
printDataMap.put("医嘱备注", Helper.ToStr(visExt.ReqNotes));
printDataMap.put("医嘱名称", rep.TestSetName);
printDataMap.put("申请医生", EntityManager().DolerGetCName(BTDoctor.class, vis.DoctorDR));
printDataMap.put("申请日期", Helper.DateIntToStr(vis.RequestDate));
printDataMap.put("初审者", EntityManager().DolerGetCName(SYSUser.class, rep.EntryUserDR));
printDataMap.put("初审者签名", Helper.ToStr(EntityManager().DolerGetCol(SYSUser.class, rep.EntryUserDR, "Code")));
printDataMap.put("初审日期", Helper.DateIntToStr(rep.EntryDate));
printDataMap.put("初审时间", Helper.TimeIntToStr(rep.EntryTime));
printDataMap.put("审核者", EntityManager().DolerGetCName(SYSUser.class, rep.AuthUserDR));
printDataMap.put("审核日期", Helper.DateIntToStr(rep.AuthDate));
printDataMap.put("审核时间", Helper.TimeIntToStr(rep.AuthTime));
printDataMap.put("审核者签名", Helper.ToStr(EntityManager().DolerGetCol(SYSUser.class, rep.AuthUserDR, "Code")));
printDataMap.put("出生日期", Helper.DateIntToStr(visExt.BirthDate));
printDataMap.put("仪器名称", "");
printDataMap.put("流水号", rep.EpisodeNo);
printDataMap.put("病案号", vis.MedicalRecordNo);
printDataMap.put("病区", EntityManager().DolerGetCName(BTWard.class, vis.WardDR));
printDataMap.put("血型", EntityManager().DolerGetCName(BTABOBG.class, visExt.AboDR) + EntityManager().DolerGetCName(BTRHBG.class, visExt.RhDR));
printDataMap.put("电话", Helper.ToStr(visExt.MobileNo));
printDataMap.put("地址", Helper.ToStr(visExt.Address));
printDataMap.put("接收者", EntityManager().DolerGetCName(SYSUser.class, vis.ReceiveUserDR));
printDataMap.put("接收者签名", Helper.ToStr(EntityManager().DolerGetCol(SYSUser.class, vis.ReceiveUserDR, "Code")));
printDataMap.put("接收日期", Helper.DateIntToStr(vis.ReceiveDate));
printDataMap.put("接收时间", Helper.TimeIntToStr(vis.ReceiveTime));
printDataMap.put("打印时间", Helper.GetNowDateStr());
printDataMap.put("核收日期", Helper.DateIntToStr(rep.AcceptDate));
printDataMap.put("核收时间", Helper.TimeIntToStr(rep.AcceptTime));
printDataMap.put("核收者", EntityManager().DolerGetCName(SYSUser.class, rep.AcceptUserDR));
printDataMap.put("核收者签名", Helper.ToStr(EntityManager().DolerGetCol(SYSUser.class, rep.AcceptUserDR, "Code")));
printDataMap.put("报告评价", Helper.ToStr(repExt.MajorConclusion));
printDataMap.put("标本质量", EntityManager().DolerGetCName(BTSpecimenQuality.class, vis.SpecimenQualityDR));
BTWorkGroupMachine wgm = EntityManager().DolerGet(BTWorkGroupMachine.class, rep.WorkGroupMachineDR);
printDataMap.put("工作小组", wgm.CName);
BTWorkGroup wg = EntityManager().DolerGet(BTWorkGroup.class, wgm.WorkGroupDR);
printDataMap.put("工作组", wg.CName);
printDataMap.put("报告说明", Helper.ToStr(repExt.ReportRemark));
BTHospital hos = EntityManager().DolerGet(BTHospital.class, vis.HospitalDR);
printDataMap.put("标题", hos.CName + wg.CName + "检验报告单");
printDataMap.put("采集部位", EntityManager().DolerGetCName(BTAnatomicalSite.class, vis.AnatomicalSiteDR));
printDataMap.put("患者类型", EntityManager().DolerGetCName(BTAdmissionType.class, vis.AdmissionTypeDR));
printDataMap.put("证件类型", EntityManager().DolerGetCName(BTCertType.class, visExt.CertTypeDR));
printDataMap.put("证件号", Helper.ToStr(visExt.CertNo));
if (vis.Urgent != null && vis.Urgent == 1) {
printDataMap.put("加急", "急");
} else {
printDataMap.put("加急", "");
}
printDataMap.put("身份证号", Helper.ToStr(vis.IDNumber));
printDataMap.put("采集者", EntityManager().DolerGetCName(SYSUser.class, vis.CollectUserDR));
printDataMap.put("采集者签名", Helper.ToStr(EntityManager().DolerGetCol(SYSUser.class, vis.CollectUserDR, "Code")));
}
/**
* 得到报告图片数据
*
* @param reprtDR
* @return
*/
private HashMap<String, String> MakePrintImageData(long reprtDR) throws Exception {
HashMap<String, String> out = new HashMap<>();
List<RPVisitNumberReportImage> imgList = EntityManager().FindByColVal(RPVisitNumberReportImage.class, "VisitNumberReportDR", reprtDR);
if (imgList != null && imgList.size() > 0) {
String fileService = (String) Helper.GetBllMethodData("common.GetParaCommon", "GetFileServiceAddr", EntityManager());
for (RPVisitNumberReportImage img : imgList) {
out.put(img.ImageClass, fileService + img.FileName);
}
}
return out;
}
/**
* 输出报告结果
*
* @param template
* @param template 模板
* @param retList 元素列表
* @param repResList 报告结果列表
*/
private void PrintDataGrid(JRTPrintTemplateDto template, List<PrintElement> retList, List<Object> repResList) throws Exception {
for (JRTPrintTemplateEle ele : template.EleList) {
//输出表格
if (ele.PrintType.equals("DataGrid")) {
if (!ele.DataField.equals("Result")) {
continue;
}
//得到表格定义
GridDto defGrid = (GridDto) Helper.Json2Object(ele.PrintText, GridDto.class);
int lastY = PrintDrawProtocol.DrawGrid(retList, defGrid, null, repResList, "ReportRes", this);
int index = 0;
for (Object one : repResList) {
HashMap repRes = (HashMap) one;
//有药敏结果的输出药敏
if (repRes.containsKey("AntSen")) {
List<Object> antSenList = (List<Object>) repRes.get("AntSen");
GridDto antGrid = GetAntGridDef();
index++;
if (index == 1) {
//第一个菌接着结果后面打印
antGrid.PageList.get(0).Top = lastY;
} else {
//第二个菌从结果位置打印
antGrid.PageList.get(0).Top = ele.PrintY.intValue();
}
if (antGrid != null&&antSenList.size()>0) {
lastY = PrintDrawProtocol.DrawGrid(retList, antGrid, null, antSenList, "AntSen", this);
}
//打印专家规则
String expertRule=(String)repRes.get("专家规则");
if(Helper.IsNotEmptyStr(expertRule)) {
List<Object> expertList=new ArrayList<>();
HashMap expertHs=new HashMap();
expertHs.put("data","专家规则:");
expertList.add(expertHs);
expertHs=new HashMap();
expertHs.put("data",expertRule);
expertList.add(expertHs);
GridDto def=GetOneColGrid(antGrid.PageList.get(0).Left,lastY-antGrid.RowHeight, GridDraw.GetGridWidth(antGrid));
lastY = PrintDrawProtocol.DrawGrid(retList, def, null, expertList, "ExpertRule", this);
}
//打印备注
String remark=(String)repRes.get("备注");
if(Helper.IsNotEmptyStr(remark)) {
List<Object> remarkList=new ArrayList<>();
HashMap eremarkHs=new HashMap();
eremarkHs.put("data","备注:");
remarkList.add(eremarkHs);
eremarkHs=new HashMap();
eremarkHs.put("data",remark);
remarkList.add(eremarkHs);
GridDto def=GetOneColGrid(antGrid.PageList.get(0).Left,lastY-antGrid.RowHeight, GridDraw.GetGridWidth(antGrid));
lastY = PrintDrawProtocol.DrawGrid(retList, def, null, remarkList, "Remark", this);
}
//打印耐药机制
String rstRes=(String)repRes.get("耐药机制");
if(Helper.IsNotEmptyStr(rstRes)) {
List<Object> rstResList=new ArrayList<>();
HashMap rstResHs=new HashMap();
rstResHs.put("data","耐药机制:");
rstResList.add(rstResHs);
rstResHs=new HashMap();
rstResHs.put("data",rstRes);
rstResList.add(rstResHs);
GridDto def=GetOneColGrid(antGrid.PageList.get(0).Left,lastY-antGrid.RowHeight, GridDraw.GetGridWidth(antGrid));
lastY = PrintDrawProtocol.DrawGrid(retList, def, null, rstResList, "RstRes", this);
}
//不同的菌输出一个换页
retList.add(PrintDrawProtocol.ChangePage());
}
}
}
}
}
/**
* 得到只有一列的无边框表格来画长的换行串
* @param left 左边
* @param top 顶部
* @param width 宽度
* @return
*/
private GridDto GetOneColGrid(int left,int top,int width)
{
//这部分由设计器维护的Json得到表格维护信息
GridDto def = new GridDto();
//边框宽度
def.BoderWidth=0;
//列数
def.Cols=1;
//是否左填充
def.ColsLeftFull=0;
//第一页控制参数
GridPageDto page = new GridPageDto();
//换页行数
page.ChangePageRowNum=999;
page.Left=left;
//顶部
page.Top=top;
def.PageList.add(page);
//定义表格的列
GridColDto col = new GridColDto();
col = new GridColDto();
col.DataField = "data";
col.Width = width;
def.DataCol.add(col);
return def;
}
/**
* 输出固定图片
*
* @param template
* @param template 模板
* @param retList 元素列表
*/
private void PrintFixImage(JRTPrintTemplateDto template, List<PrintElement> retList) {
for (JRTPrintTemplateEle ele : template.EleList) {
try {
//输出图片
if (ele.PrintType.equals("Graph")) {
boolean isSign = false;
if (ele.PrintFlag.equals("D")) {
isSign = true;
}
String dataField = ele.DataField;
//不是图标的,且不包含https的不打印
if (isSign == false && !dataField.contains("http")) {
continue;
}
//取图标书记
if (isSign) {
HashParam hs = new HashParam();
hs.Add("Code", dataField);
hs.Add("ImgType", "DEF");
JRTPrintImage printImage = EntityManager().GetByPara(JRTPrintImage.class, hs);
if (printImage != null) {
dataField = printImage.ImgBase64String;
}
}
PrintElement printEle = PrintDrawProtocol.DrawGraph(ele.PrintX, ele.PrintY, ele.PrintWidth, ele.PrintHeight, dataField, isSign, false);
retList.add(printEle);
}
}
catch (Exception ex)
{
Helper.WriteExceptionLog("打印图片异常",ex);
}
}
}
/**
* 输出报告图片
*
* @param template
* @param template 模板
* @param retList 元素列表
* @param printDataMap 数据图
*/
private void PrintReportImage(JRTPrintTemplateDto template, List<PrintElement> retList, HashMap<String, String> printDataMap) {
for (JRTPrintTemplateEle ele : template.EleList) {
//输出图片
if (ele.PrintType.equals("Graph")) {
boolean isSign = false;
if (ele.PrintFlag.equals("D")) {
isSign = true;
}
String dataField = ele.DataField;
if (!ele.DataField.isEmpty() && printDataMap.containsKey(ele.DataField)) {
dataField = printDataMap.get(ele.DataField);
} else {
continue;
}
PrintElement printEle = PrintDrawProtocol.DrawGraph(ele.PrintX, ele.PrintY, ele.PrintWidth, ele.PrintHeight, dataField, isSign, false);
retList.add(printEle);
}
}
}
/**
* 输出水印
*
* @param template 模板
* @param retList 元素列表
*/
private void PrintWaterMark(JRTPrintTemplateDto template, List<PrintElement> retList) {
String paperCode="A5";
if(template.JRTPrintPaperDR!=null)
{
try {
JRTPrintPaper paper = EntityManager().DolerGet(JRTPrintPaper.class, template.JRTPrintPaperDR);
paperCode = paper.Code;
}
catch (Exception ex)
{
LogUtils.WriteExceptionLog("打印输出水印异常:",ex);
}
}
int width=827;
int heigth=583;
if(paperCode.equals("A4"))
{
heigth=1169;
}
for(int x=10;x<width;x+=170)
{
for(int y=10;y<heigth;y+=200)
{
PrintElement printEle = PrintDrawProtocol.DrawLabel(x, y, waterMark, "宋体", 12, "", null, "#AAAAAA", "", "45");
retList.add(printEle);
}
}
}
/**
* 输出数据
*
* @param template 模板
* @param retList 元素列表
* @param printDataMap 数据哈希
*/
private void PrintData(JRTPrintTemplateDto template, List<PrintElement> retList, Hashtable<String, String> printDataMap) {
for (JRTPrintTemplateEle ele : template.EleList) {
//输出标签
if (ele.PrintType.equals("Data")) {
String dataFiled = ele.DataField;
if (!dataFiled.isEmpty() && printDataMap.containsKey(dataFiled)) {
//带字的条码
if (ele.PrintFlag.contains("BarCode")) {
String BarType = ele.PrintFlag.replace("BarCode", "");
PrintElement printEle = PrintDrawProtocol.DrawBarCode(ele.PrintX, ele.PrintY, printDataMap.get(dataFiled), true, ele.PrintWidth, ele.PrintHeight, BarType, ele.PrintFont, Convert.ToDouble(ele.PrintFontSize).intValue(), ele.PrintFontStyle, PrintDrawProtocol.GetPrintAlignment(ele.PrintAlignment), ele.Color, ele.Angle);
retList.add(printEle);
}
//不带字的条码
else if (ele.PrintFlag.contains("BarCodeN")) {
String BarType = ele.PrintFlag.replace("BarCodeN", "");
PrintElement printEle = PrintDrawProtocol.DrawBarCode(ele.PrintX, ele.PrintY, printDataMap.get(dataFiled), false, ele.PrintWidth, ele.PrintHeight, BarType, ele.PrintFont, Convert.ToDouble(ele.PrintFontSize).intValue(), ele.PrintFontStyle, PrintDrawProtocol.GetPrintAlignment(ele.PrintAlignment), ele.Color, ele.Angle);
retList.add(printEle);
}
//画普通数据
else {
PrintElement printEle = PrintDrawProtocol.DrawLabel(ele.PrintX, ele.PrintY, printDataMap.get(dataFiled), ele.PrintFont, Convert.ToDouble(ele.PrintFontSize).intValue(), ele.PrintFontStyle, PrintDrawProtocol.GetPrintAlignment(ele.PrintAlignment), ele.Color, "", ele.Angle);
retList.add(printEle);
}
}
}
}
}
/**
* 输出标签
*
* @param template
* @param retList
*/
private void PrintLabel(JRTPrintTemplateDto template, List<PrintElement> retList) {
for (JRTPrintTemplateEle ele : template.EleList) {
//输出标签
if (ele.PrintType.equals("Label")) {
PrintElement printEle = PrintDrawProtocol.DrawLabel(ele.PrintX, ele.PrintY, ele.PrintText, ele.PrintFont, Convert.ToDouble(ele.PrintFontSize).intValue(), ele.PrintFontStyle, PrintDrawProtocol.GetPrintAlignment(ele.PrintAlignment), ele.Color, "", ele.Angle);
retList.add(printEle);
}
}
}
/**
* 输出线
*
* @param template
* @param retList
*/
private void PrintLine(JRTPrintTemplateDto template, List<PrintElement> retList) {
for (JRTPrintTemplateEle ele : template.EleList) {
//输出先
if (ele.PrintType.equals("ILineN")) {
long width = ele.PrintWidth;
long height = ele.PrintHeight;
long endX = ele.PrintX + width;
long endY = ele.PrintY;
long lineWidth = height;
if (height > width) {
endX = ele.PrintX;
endY = ele.PrintY;
lineWidth = width;
}
PrintElement printEle = PrintDrawProtocol.DrawLine(ele.PrintX, ele.PrintY, endX, endY, lineWidth, ele.PrintFlag, ele.Color);
retList.add(printEle);
}
}
}
/**
* 通过模板主键或者代码得到模板数据供打印使用
*
* @param rowID
* @param code
* @return
*/
private JRTPrintTemplateDto GetOneTemplate(Long rowID, String code) throws Exception {
JRTPrintTemplateDto retDto = null;
//按主键取
if (rowID != null) {
retDto = EntityManager().GetById(JRTPrintTemplateDto.class, rowID);
}
//按代码取
else if (code != null && !code.isEmpty()) {
retDto = EntityManager().GetByColVal(JRTPrintTemplateDto.class, "Code", code);
}
if (retDto != null) {
HashParam hs = new HashParam();
hs.Add("PrintTemplateDR", retDto.RowID);
retDto.EleList = EntityManager().FindAllSimple(JRTPrintTemplateEle.class, hs);
}
return retDto;
}
/**
* 得到抗生素表格定义
*
* @return
* @throws Exception
*/
private GridDto GetAntGridDef() throws Exception {
for (JRTPrintTemplateEle ele : template.EleList) {
//输出表格
if (ele.PrintType.equals("DataGrid")) {
if (!ele.DataField.equals("AntSen")) {
continue;
}
//得到表格定义
GridDto defGrid = (GridDto) Helper.Json2Object(ele.PrintText, GridDto.class);
return defGrid;
}
}
return null;
}
/**
* 翻译结果标识
*
* @param abFlag
* @return
*/
private String TransAbFlag(String abFlag) {
if (abFlag == null) {
return "";
}
if (abFlag.equals("L")) {
abFlag = "↓";
} else if (abFlag.equals("H")) {
abFlag = "↑";
} else if (abFlag.equals("PL")) {
abFlag = "↓↓↓";
} else if (abFlag.equals("PH")) {
abFlag = "↑↑↑";
} else if (abFlag.equals("A")) {
abFlag = "*";
} else if (abFlag.equals("S")) {
abFlag = "***";
}
return abFlag;
}
/**
* 存获得的一个模板数据
*/
public static class JRTPrintTemplateDto extends JRTPrintTemplate {
/**
* 模板元素
*/
public List<JRTPrintTemplateEle> EleList;
}
}
代码关联示例
import JRT.Model.Entity.JRTPrintTemplate;
import JRTBLLBase.BaseHttpHandler;
/**
* 代码关联的示例
*/
public class CodeDefDemo extends BaseHttpHandler {
/**
* 供配置代码关联,配置格式vmprint.CodeDegDemo^GetCodeDef
* @param reportDR
* @param tempDR
* @return
*/
public long GetCodeDef(long reportDR,long tempDR) throws Exception
{
//实际情况根据传入的报告主键和模板主键决定返回的模板,这里固定代码的模板返回测试
JRTPrintTemplate temp=EntityManager().GetByColVal(JRTPrintTemplate.class,"Code","ReportPrint");
if(temp!=null)
{
return temp.RowID;
}
return tempDR;
}
}
好马配好鞍,最强lis才是jrtlis的目标,最强信创才是jrt的目标