JRT打印鉴定记录单

良好的基础会使上层实现越做越简单,jrt在开始写业务之前就把运用场景需要的基础实验和设计完毕了。基于jrt的基础可以很轻松的实现强大的打印效果。jrt的打印和lodop比较像,是高度为满足建议系统打印定制的打印实现,设计器可能没lodop通用,但是画布统一,可以容易的实现在线预览、得到pdf、图片、控制粒度细、支持Windows、Linux。是自主可控的医疗信创打印不二之选。

这次分享个打印记录单的效果和业务代码
在这里插入图片描述

在这里插入图片描述
打印逻辑

/*
本代码权归属于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.MultiPlatform.JRTContext;
import JRT.Core.Util.Convert;
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 LISPrintIDPProcess extends BaseHttpHandlerNoSession implements IGridChangePage {

    /**
     * 打印元素
     */
    private List<PrintElement> retList = new ArrayList<>();

    /**
     * 打印模板数据
     */
    JRTPrintTemplateDto template = null;

    /**
     * 存打印的Data数据
     */
    Hashtable<String, String> printDataMap = null;

    /**
     * 最后绘图的Y
     */
    private int lastY=0;

    /**
     * 表格换页之前要执行的逻辑
     *
     * @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("换页后执行逻辑");
        //画固定图片元素
        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);
            //查询模板数据
            template = GetOneTemplate(null, "IDPProcessPrint");
            //换报告之后无脑输出一个分页
            retList.add(PrintDrawProtocol.ChangePage());
            //查询并且填充Data
            MakePrintDataMap(reportDR);
            //查询结果数据
            List<Object> repResList = MakePrintResultData(reportDR);
            //画固定图片元素
            PrintFixImage(template, retList);
            //画数据元素
            PrintData(template, retList, printDataMap);
            //画标签元素
            PrintLabel(template, retList);
            //画线元素
            PrintLine(template, retList);
            PrintIDPCultureMedRes(template, retList,reportDR);
            PrintIDPUpMach(template, retList,reportDR);
            //画表格元素
            PrintAntDataGrid(template, retList, repResList);

        }
        return Helper.Object2Json(retList);
    }

    /**
     * 输出培养基信息
     * @param template 模板
     * @param retList 元素列表
     * @param reportDR 报告主键
     * @throws Exception
     */
    private void PrintIDPCultureMedRes(JRTPrintTemplateDto template, List<PrintElement> retList,long reportDR) throws Exception
    {
        List<Object> gridData = new ArrayList<>();
        List<IDPResult> idpList = EntityManager().FindByColVal(IDPResult.class, "VisitNumberReportDR", reportDR);
        if (idpList != null && idpList.size() > 0) {
            for (IDPResult idp : idpList) {
                String remark = Helper.ToStr(idp.Remark);
                List<IDPCultureMedPakRes> pakList = EntityManager().FindByColVal(IDPCultureMedPakRes.class, "IDPResultDR", idp.RowID);
                if (pakList != null && pakList.size() > 0) {
                    for (IDPCultureMedPakRes pak : pakList) {
                        String cultureMedPak = EntityManager().DolerGetCName(BTIDPCultureMedPak.class, pak.IDPCultureMedPakDR);
                        List<IDPCultureMedRes> medList = EntityManager().FindByColVal(IDPCultureMedRes.class, "IDPResultDR", idp.RowID);
                        if (medList != null && medList.size() > 0) {
                            for (IDPCultureMedRes med : medList) {
                                String idpCultureMedium = EntityManager().DolerGetCName(BTIDPCultureMedium.class, med.IDPCultureMediumDR);
                                String name = "[" + med.RowID + "]" + idpCultureMedium;
                                String cultureDesk = Helper.ToStr(med.CultureDesk);
                                String fromInfo = remark + "-" + idpCultureMedium + ":" + cultureDesk;
                                HashMap oneRow = new HashMap();
                                oneRow.put("培养基", idpCultureMedium);
                                if (Helper.IsNotEmptyStr(med.CultureDesk)&&Helper.IsNumeric(med.CultureDesk)) {
                                    oneRow.put("形态描述", Helper.ToStr(EntityManager().DolerGetCol(BTIDPCultureDesk.class, Convert.ToLong(med.CultureDesk), "Remark")));
                                } else {
                                    oneRow.put("形态描述", "");
                                }
                                oneRow.put("菌落计数", med.Num);
                                oneRow.put("容器", med.ContainerCode);
                                oneRow.put("拉丝试验", med.Special);
                                oneRow.put("生化反应", med.BioReaction);
                                oneRow.put("百分百", med.Rate);
                                oneRow.put("上机类型", EntityManager().DolerGetCName(BTIDPMach.class,med.IDPMachDR));
                                oneRow.put("快速鉴定", EntityManager().DolerGetCName(BTOrganism.class,med.OrganismDR));
                                oneRow.put("菌落颜色", med.OrgColor);
                                oneRow.put("菌落大小", med.OrgSize);
                                oneRow.put("湿度", med.OrgHumidity);
                                oneRow.put("菌类型", med.OrgType);
                                oneRow.put("粘稠度", med.OrgViscosity);
                                oneRow.put("边缘", med.OrgEdge);
                                oneRow.put("其他说明", med.OrgRemark);
                                gridData.add(oneRow);
                            }
                        }
                    }
                }
            }
        }

        for (JRTPrintTemplateEle ele : template.EleList) {
                //输出表格
                if (ele.PrintType.equals("DataGrid")) {
                    if (!ele.DataField.equals("IDPCultureMedRes")) {
                        continue;
                    }
                    //得到表格定义
                    GridDto defGrid = (GridDto) Helper.Json2Object(ele.PrintText, GridDto.class);
                    PrintElement printEle = PrintDrawProtocol.DrawLabel(defGrid.PageList.get(0).Left, defGrid.PageList.get(0).Top, "培养记录", "宋体", 12, "Bold", null, "", "", "");
                    defGrid.PageList.get(0).Top+=20;
                    retList.add(printEle);
                    lastY=defGrid.PageList.get(0).Top;
                    if(gridData.size()>0) {
                        lastY = PrintDrawProtocol.DrawGrid(retList, defGrid, null, gridData, "IDPCultureMedRes", this);
                    }
                }
        }
    }

    /**
     * 输出培养基信息
     * @param template 模板
     * @param retList 元素列表
     * @param reportDR 报告主键
     * @throws Exception
     */
    private void PrintIDPUpMach(JRTPrintTemplateDto template, List<PrintElement> retList,long reportDR) throws Exception
    {
        List<Object> gridData = new ArrayList<>();
        List<IDPResult> idpList = EntityManager().FindByColVal(IDPResult.class, "VisitNumberReportDR", reportDR);
        if (idpList != null && idpList.size() > 0) {
            for (IDPResult idp : idpList) {
                String remark = Helper.ToStr(idp.Remark);
                List<IDPUpMach> list = EntityManager().FindByColVal(IDPUpMach.class, "IDPResultDR", idp.RowID);
                if (list != null && list.size() > 0) {
                    for (IDPUpMach one : list) {
                        HashMap oneRow = new HashMap();
                        oneRow.put("培养结果", one.TxtResult);
                        oneRow.put("上机仪器", EntityManager().DolerGetCName(BTIDPMach.class,one.IDPMachDR));
                        oneRow.put("板条类型", Helper.ToStr(EntityManager().DolerGetCol(BTIDPSlats.class,one.IDPSlatsDR,"SlatsCName")));
                        oneRow.put("板条批号", one.SlatsNo);
                        oneRow.put("上机备注", one.Remark);
                        oneRow.put("上机ID", one.UpID);
                        oneRow.put("上机人", EntityManager().DolerGetCName(SYSUser.class,one.UpMachUserDR));
                        oneRow.put("上机日期", Helper.DateIntToStr(one.UpMachDate));
                        oneRow.put("上机时间", Helper.TimeIntToStr(one.UpMachTime));
                        gridData.add(oneRow);
                    }
                }
            }
        }
        if(gridData.size()>0) {
            for (JRTPrintTemplateEle ele : template.EleList) {
                //输出表格
                if (ele.PrintType.equals("DataGrid")) {
                    if (!ele.DataField.equals("IDPUpMach")) {
                        continue;
                    }
                    //得到表格定义
                    GridDto defGrid = (GridDto) Helper.Json2Object(ele.PrintText, GridDto.class);
                    lastY+=20;
                    PrintElement printEle = PrintDrawProtocol.DrawLabel(defGrid.PageList.get(0).Left, lastY, "上机记录", "宋体", 12, "Bold", null, "", "", "");
                    retList.add(printEle);
                    defGrid.PageList.get(0).Top=lastY+20;
                    lastY = PrintDrawProtocol.DrawGrid(retList, defGrid, null, gridData, "IDPUpMach", this);
                }
            }
        }
    }

    /**
     * 构造打印的报告结果数据
     *
     * @param reportDR 报告主键
     * @return
     */
    private List<Object> MakePrintResultData(long reportDR) throws Exception {
        List<Object> retList = new ArrayList<>();
        List<IDPResult> idpList=EntityManager().FindByColVal(IDPResult.class,"VisitNumberReportDR",reportDR);
        List<Long> repDRS=new ArrayList<>();
        if(idpList!=null&&idpList.size()>0)
        {
            for(IDPResult one:idpList)
            {
                if(one.LinkReportDR!=null)
                {
                    repDRS.add(one.LinkReportDR);
                }
            }
        }
        if(repDRS.size()==0)
        {
            repDRS.add(reportDR);
        }
        //查询药敏结果
        for(Long oneRepDR:repDRS) {
            List<RPVisitNumberReportResult> resList = EntityManager().FindByColVal(RPVisitNumberReportResult.class, "VisitNumberReportDR", oneRepDR);
            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);
                    if (!tsDto.ResultFormat.equals("M")) {
                        continue;
                    }
                    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("诊断", visExt.Symptom);
        printDataMap.put("采集日期", Helper.DateIntToStr(vis.CollectDate));
        printDataMap.put("采集时间", Helper.TimeIntToStr(vis.CollectTime));
        printDataMap.put("医嘱备注", 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("电话", visExt.MobileNo);
        printDataMap.put("地址", 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("报告评价", 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("报告说明", 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("证件号", visExt.CertNo);
        if (vis.Urgent != null && vis.Urgent == 1) {
            printDataMap.put("加急", "急");
        } else {
            printDataMap.put("加急", "");
        }
        printDataMap.put("身份证号", 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 PrintAntDataGrid(JRTPrintTemplateDto template, List<PrintElement> retList, List<Object> repResList) throws Exception {
        int index = 0;
        for (Object one : repResList) {
            HashMap repRes = (HashMap) one;
            GridDto antGrid = GetAntGridDef();
            lastY+=20;
            PrintElement printEle = PrintDrawProtocol.DrawLabel(antGrid.PageList.get(0).Left, lastY, Helper.ToStr(repRes.get("结果")), "宋体", 12, "Bold", null, "", "", "");
            retList.add(printEle);
            //有药敏结果的输出药敏
            if (repRes.containsKey("AntSen")) {
                List<Object> antSenList = (List<Object>) repRes.get("AntSen");

                index++;
                if (antGrid != null&&antSenList.size()>0) {
                    antGrid.PageList.get(0).Top = lastY+20;
                    lastY = PrintDrawProtocol.DrawGrid(retList, antGrid, null, antSenList, "AntSen", 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 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(Integer 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;
    }

}


相关推荐

  1. 富格林:正规鉴别暗箱套路

    2024-07-15 09:50:04       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 09:50:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 09:50:04       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 09:50:04       58 阅读
  4. Python语言-面向对象

    2024-07-15 09:50:04       69 阅读

热门阅读

  1. 对AAC解码的理解

    2024-07-15 09:50:04       22 阅读
  2. 【Karapathy大神build-nanogpt】Take Away Notes

    2024-07-15 09:50:04       24 阅读
  3. C的分文件编写与动态库

    2024-07-15 09:50:04       26 阅读
  4. Spring Boot中的安全配置与实现

    2024-07-15 09:50:04       20 阅读
  5. 设计模式--抽象工厂模式

    2024-07-15 09:50:04       23 阅读
  6. 【C++ 】类与对象 -- 纯虚函数与抽象类

    2024-07-15 09:50:04       22 阅读
  7. 设计模式--简单(抽象)工厂模式

    2024-07-15 09:50:04       24 阅读