| | |
| | | import com.itextpdf.text.pdf.*; |
| | | import com.itextpdf.text.pdf.draw.LineSeparator; |
| | | import com.ltkj.common.core.domain.AjaxResult; |
| | | import com.ltkj.common.core.domain.entity.SysDictData; |
| | | import com.ltkj.common.core.domain.entity.SysUser; |
| | | import com.ltkj.common.utils.DateUtils; |
| | | import com.ltkj.common.utils.StringUtils; |
| | | import com.ltkj.framework.config.MatchUtils; |
| | | import com.ltkj.hosp.domain.*; |
| | | import com.ltkj.hosp.service.ITjCustomerService; |
| | | import com.ltkj.hosp.service.ITjOrderService; |
| | | import com.ltkj.hosp.service.ITjReportService; |
| | | import com.ltkj.hosp.service.ITjReportTemplateService; |
| | | import com.ltkj.hosp.service.*; |
| | | import com.ltkj.hosp.sqlDomain.LtkjHybgd; |
| | | import com.ltkj.hosp.sqlDomain.LtkjHysqd; |
| | | import com.ltkj.mall.mallOrderUtils.TjConstants; |
| | | import com.ltkj.system.service.ISysDictDataService; |
| | | import com.ltkj.system.service.ISysUserService; |
| | | import com.ltkj.web.config.pdfutils.PdfUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.lang.reflect.Method; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | |
| | |
| | | private ITjCustomerService tjCustomerService; |
| | | @Autowired |
| | | private ITjReportService tjReportService; |
| | | @Autowired |
| | | private ITjProjectService projectService; |
| | | @Autowired |
| | | private ITjOrderRemarkService tjOrderRemarkService; |
| | | @Autowired |
| | | private ITjOrderDetailService tjOrderDetailService; |
| | | @Autowired |
| | | private ITjStandardService tjStandardService; |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | @Autowired |
| | | private IDictCompService dictCompService; |
| | | @Autowired |
| | | private ITjBigPositiveService tjBigPositiveService; |
| | | @Autowired |
| | | private LtkjHybgdService ltkjHybgdService; |
| | | @Autowired |
| | | private LtkjHysqdService ltkjHysqdService; |
| | | @Value("${path.filePath}") |
| | | private String value; |
| | | @Value("${path.reportServer}") |
| | | private String urlValue; |
| | | |
| | | // private static final |
| | | |
| | | /** |
| | | * 通过his API请求获取数据生成PDF |
| | | * @param pdfInfoMap |
| | | * @param params |
| | | * @param tjOrder |
| | | * @param tjReportTemplate |
| | | * @return |
| | | * @deprecated 有数据同步不在调用接口获取数据直接查数据库拿数据生成 |
| | | */ |
| | | @Deprecated |
| | | public AjaxResult execHisRequest(HashMap<String, Object> pdfInfoMap, Map<String, Object> params,TjOrder tjOrder,TjReportTemplate tjReportTemplate) { |
| | | List<Map<String, Object>> list; |
| | | String hisRegistrationId = params.get("his_registration_id").toString(); |
| | |
| | | JSONObject obj = JSONUtil.createObj(); |
| | | putData(obj, getexamreportinfo, "检查报告"); |
| | | jsonArray.put(obj); |
| | | System.out.println(JSONUtil.toJsonStr(jsonArray)); |
| | | if (makePDF(hisRegistrationId, jsonArray,tjOrder,tjReportTemplate)) |
| | | // System.out.println(JSONUtil.toJsonStr(jsonArray)); |
| | | if (makePDF(hisRegistrationId, jsonArray,tjOrder,tjReportTemplate)) { |
| | | log.info("已生成报告"); |
| | | return AjaxResult.success("已生成报告!可直接点击预览!"); |
| | | else return AjaxResult.error(); |
| | | } else return AjaxResult.error(); |
| | | } else { |
| | | return AjaxResult.error("未获取到检验报告记录信息"); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public AjaxResult hisPDF(TjOrder tjOrder,TjCustomer customer,TjReportTemplate tjReportTemplate) throws DocumentException { |
| | | HashMap<String, Object> pdfChangGui = makePDFInfo(tjOrder, customer, tjReportTemplate); |
| | | Document document = (Document) pdfChangGui.get("document"); |
| | | PdfCopy copy = (PdfCopy) pdfChangGui.get("copy"); |
| | | ByteArrayOutputStream finalOutPut = (ByteArrayOutputStream) pdfChangGui.get("stream"); |
| | | ByteArrayOutputStream byteArrayOutputStream1 = new ByteArrayOutputStream(); |
| | | Document document1 = new Document(PageSize.A4); |
| | | PdfWriter pdfWriter = null; |
| | | try { |
| | | pdfWriter = PdfWriter.getInstance(document1, byteArrayOutputStream1); |
| | | } catch (DocumentException e) { |
| | | e.printStackTrace(); |
| | | return AjaxResult.error(); |
| | | } |
| | | document1.setMargins(70, 70, 40, 40); |
| | | document1.open(); |
| | | // 非化验项目报告 |
| | | Map<TjOrderRemark, List<TjPdfVO>> printReport = new HashMap<>(); |
| | | notHuaYanData(tjOrder.getTjNumber(), printReport,tjOrder,customer); |
| | | try { |
| | | notHuaYanTable(document1, printReport); |
| | | } catch (DocumentException e) { |
| | | log.error("非化验项目填充表格异常"); |
| | | e.printStackTrace(); |
| | | return AjaxResult.error(); |
| | | } |
| | | // 组装检验数据 |
| | | HashMap<String, Object> map = makeHisJianYan(tjOrder, customer); |
| | | makeHisJianYanTable(document1, map); |
| | | |
| | | document1.close(); |
| | | pdfWriter.close(); |
| | | PdfReader reader = null; |
| | | try { |
| | | reader = new PdfReader(byteArrayOutputStream1.toByteArray()); |
| | | int numberOfPages1 = reader.getNumberOfPages(); |
| | | for (int i = 1; i <= numberOfPages1; i++) { |
| | | PdfImportedPage page = copy.getImportedPage(reader, i); |
| | | copy.addPage(page); |
| | | } |
| | | reader.close(); |
| | | byteArrayOutputStream1.close(); |
| | | document.close(); |
| | | copy.close(); |
| | | } catch (IOException e) { |
| | | log.error("拷贝pdf异常"); |
| | | e.printStackTrace(); |
| | | return AjaxResult.error(); |
| | | } |
| | | String outputFileName1 = customer.getCusId() + tjOrder.getTjNumber() + customer.getCusName() + "_报告.pdf"; |
| | | savePDFFile(outputFileName1,tjOrder, customer, finalOutPut); |
| | | TjReport tjReport = new TjReport(); |
| | | String tjNumber = tjOrder.getTjNumber(); |
| | | tjReport.setTjNumber(String.valueOf(tjNumber)); |
| | | tjReport.setPath(urlValue + outputFileName1); |
| | | // TODO 文件配置 |
| | | // String outputPath1 = "/Users/chacca/开发相关/代码/"; |
| | | String outputPath1 = value+"\\"; |
| | | String pdfBinary = getPDFBinary(outputPath1 + outputFileName1); |
| | | tjReport.setReport(pdfBinary); |
| | | tjReport.setType("体检报告"); |
| | | tjReport.setPrint("pdf"); |
| | | tjReportService.save(tjReport); |
| | | LambdaUpdateWrapper<TjOrder> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(TjOrder::getTjNumber, tjNumber); |
| | | updateWrapper.set(TjOrder::getReportTime, new Date()); |
| | | updateWrapper.set(TjOrder::getPrintLastTime, new Date()); |
| | | updateWrapper.set(TjOrder::getDownloadLastTime, new Date()); |
| | | updateWrapper.set(TjOrder::getStatus, TjConstants.TJ_END); |
| | | tjOrderService.update(updateWrapper); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * PDF文件存储至本地 |
| | | * @param tjOrder |
| | | * @param customer |
| | | * @param finalOutPut |
| | | */ |
| | | private void savePDFFile(String outputFileName1,TjOrder tjOrder, TjCustomer customer, ByteArrayOutputStream finalOutPut) { |
| | | // TODO 文件配置 |
| | | // String outputPath1 = "/Users/chacca/开发相关/代码/"; |
| | | String outputPath1 = value+"\\"; |
| | | File file = new File(outputPath1 + outputFileName1); |
| | | BufferedOutputStream outputStream = null; |
| | | try { |
| | | outputStream = new BufferedOutputStream(new FileOutputStream(file)); |
| | | outputStream.write(finalOutPut.toByteArray()); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | finalOutPut.close(); |
| | | } catch (IOException e) { |
| | | log.error("本地存储pdf异常"); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 填充检验表格数据 |
| | | * @param document1 |
| | | * @param map |
| | | * @throws DocumentException |
| | | */ |
| | | private static void makeHisJianYanTable(Document document1, HashMap<String, Object> map) throws DocumentException { |
| | | if (!map.isEmpty()){ |
| | | String[] titles = new String[]{"体检项目", "体检结果", "单位", "参考范围"}; |
| | | float[] titlesWidth = new float[]{120, 120, 120, 120}; |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | String titleName = entry.getKey().trim(); |
| | | HashMap<String, Object> entryValue = (HashMap<String, Object>) entry.getValue(); |
| | | HashSet<String> jyys = (HashSet<String>) entryValue.get("jyys"); |
| | | ArrayList<List<String>> lists = (ArrayList<List<String>>) entryValue.get("data"); |
| | | addJianYanTable(document1,titleName,titles,titlesWidth,lists); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | String doctors = ""; |
| | | for (String s : jyys) { |
| | | doctors+=s+"、"; |
| | | } |
| | | String substring = doctors.substring(0, doctors.length() - 1); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, "检验医师:"+substring); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 非化验项目表格填充 |
| | | * @param document1 |
| | | * @param printReport |
| | | * @throws DocumentException |
| | | */ |
| | | private void notHuaYanTable(Document document1, Map<TjOrderRemark, List<TjPdfVO>> printReport) throws DocumentException { |
| | | for (Map.Entry<TjOrderRemark, List<TjPdfVO>> entry : printReport.entrySet()) { |
| | | List<TjPdfVO> value = entry.getValue(); |
| | | LambdaQueryWrapper<TjProject> wqqq = new LambdaQueryWrapper<>(); |
| | | wqqq.eq(TjProject::getProId, entry.getKey().getProId()); |
| | | TjProject one11 = projectService.getOne(wqqq); |
| | | //判断该项目是否需要打印报告 |
| | | if (null != one11 && "N".equals(one11.getNeedReport())) { |
| | | continue; |
| | | } |
| | | String titleName = null; |
| | | if (null != one11 && "1".equals(one11.getResultType())) { |
| | | titleName = one11.getProName(); |
| | | // TODO 单位 |
| | | // 设置标题字体样式 |
| | | Font titleFonts = PdfUtils.setFont(9); |
| | | Paragraph paragraph = PdfUtils.setParagraph(titleFonts, titleName); |
| | | String[] titles = {"体检项目", "体检结果","单位"}; |
| | | // 获取列表数据 |
| | | //设置表头字体样式 |
| | | Font headFont = PdfUtils.setFont(9); |
| | | // 设置正文字体样式:12号 |
| | | Font textFont = PdfUtils.setFont(9); |
| | | //创建表格 将表头字体和正文字体放进去 |
| | | PdfPTable table = PdfUtils.setTable2(headFont, textFont, titles, value); |
| | | document1.add(paragraph); |
| | | document1.add(table); |
| | | //判断备注是否为空 空不能显示null |
| | | if (entry.getKey().getRemark() == null) { |
| | | entry.getKey().setRemark(""); |
| | | } |
| | | String remark = "备注:" + entry.getKey().getRemark(); |
| | | if (entry.getKey().getRemark().length() > 50) { |
| | | int j = 0; |
| | | for (int i = 0; i < remark.length() / 50; i++) { |
| | | String substring = remark.substring(j, j + 50); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | j = j + 50; |
| | | } |
| | | if (remark.length() % 50 != 0) { |
| | | String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | } |
| | | } else { |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark); |
| | | document1.add(pp); |
| | | } |
| | | //判断主检医师是否为空 空不能显示null |
| | | if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) { |
| | | //主检医师 |
| | | String doctorName = "主检医师:" + userService.getById(entry.getKey().getDoctorName()).getNickName(); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } else { |
| | | String doctorName = "主检医师:" + "无"; |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } else { |
| | | if (null != one11) { |
| | | titleName = one11.getProName(); |
| | | } else { |
| | | titleName = entry.getKey().getProName(); |
| | | } |
| | | // 设置标题字体样式 |
| | | Font titleFonts = PdfUtils.setFont(9); |
| | | Paragraph paragraph = PdfUtils.setParagraph(titleFonts, titleName); |
| | | String[] titles = {"体检项目", "体检结果", "单位", "参考范围"}; |
| | | // 获取列表数据 |
| | | //设置表头字体样式 |
| | | Font headFont = PdfUtils.setFont(9); |
| | | // 设置正文字体样式:12号 |
| | | Font textFont = PdfUtils.setFont(9); |
| | | //创建表格 将表头字体和正文字体放进去 |
| | | PdfPTable table = PdfUtils.setTable(headFont, textFont, titles, value); |
| | | document1.add(paragraph); |
| | | document1.add(table); |
| | | //判断备注是否为空 空不能显示null |
| | | if (entry.getKey().getRemark() == null) { |
| | | entry.getKey().setRemark(""); |
| | | } |
| | | String remark = "备注:" + entry.getKey().getRemark(); |
| | | if (entry.getKey().getRemark().length() > 50) { |
| | | int j = 0; |
| | | for (int i = 0; i < remark.length() / 50; i++) { |
| | | String substring = remark.substring(j, j + 50); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | j = j + 50; |
| | | } |
| | | if (remark.length() % 50 != 0) { |
| | | String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | } |
| | | } else { |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark); |
| | | document1.add(pp); |
| | | } |
| | | //判断主检医师是否为空 空不能显示null |
| | | if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) { |
| | | //主检医师 |
| | | String doctorName = "主检医师:" + userService.getById(entry.getKey().getDoctorName()).getNickName(); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } else { |
| | | String doctorName = "主检医师:" + "无"; |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public HashMap<String, Object> makeHisJianYan(TjOrder tjOrder, TjCustomer customer){ |
| | | // TODO 这里先使用查全部测试 |
| | | LambdaQueryWrapper<LtkjHysqd> ltkjHysqdLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | ltkjHysqdLambdaQueryWrapper.eq(LtkjHysqd::getTjh,tjOrder.getCardId()); |
| | | List<LtkjHysqd> list = ltkjHysqdService.list(ltkjHysqdLambdaQueryWrapper); |
| | | // List<LtkjHysqd> list = ltkjHysqdService.list(); |
| | | HashMap<String, Object> data = new HashMap<>(); |
| | | for (LtkjHysqd hysqd : list) { |
| | | LambdaQueryWrapper<LtkjHybgd> ltkjHybgdLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | ltkjHybgdLambdaQueryWrapper.eq(LtkjHybgd::getTmh,hysqd.getTmh()); |
| | | List<LtkjHybgd> hybgds = ltkjHybgdService.list(ltkjHybgdLambdaQueryWrapper); |
| | | // 大类项目名称 |
| | | String xmmc = hysqd.getXmmc(); |
| | | ArrayList<List<String>> lists = new ArrayList<>(); |
| | | HashSet<String> hashSet = new HashSet<>(); |
| | | for (LtkjHybgd hybgd : hybgds) { |
| | | // 检查项目 |
| | | String jcxm = hybgd.getJcxm(); |
| | | // 检验结果 |
| | | String jyjg = hybgd.getJyjg(); |
| | | // 结果单位 |
| | | String jgdw = hybgd.getJgdw(); |
| | | // 范围值 |
| | | String fwz = hybgd.getFwz(); |
| | | // 检验医师 |
| | | String jyys = hybgd.getJyys(); |
| | | if (jyjg != null && StrUtil.isNotBlank(jyjg) && fwz != null && StrUtil.isNotBlank(fwz)){ |
| | | try { |
| | | String[] fwzs = fwz.split("-"); |
| | | BigDecimal min = new BigDecimal(fwzs[0]); |
| | | BigDecimal max = new BigDecimal(fwzs[1]); |
| | | BigDecimal jyjgval = new BigDecimal(jyjg); |
| | | // 比较检验结果和范围值 |
| | | if (jyjgval.compareTo(min) < 0) { |
| | | // jyjg 小于范围最小值,添加下箭头 |
| | | jyjg = jyjg + " ↓"; |
| | | } else if (jyjgval.compareTo(max) > 0) { |
| | | // jyjg 大于范围最大值,添加上箭头 |
| | | jyjg = jyjg + " ↑"; |
| | | } |
| | | } catch (Exception ignored) {} |
| | | } |
| | | LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(SysUser::getUserName,jyys); |
| | | List<SysUser> sysUsers = userService.list(queryWrapper); |
| | | if (!sysUsers.isEmpty()) |
| | | hashSet.add(sysUsers.get(0).getNickName()); |
| | | ArrayList<String> strings = new ArrayList<>(); |
| | | strings.add(jcxm); |
| | | strings.add(jyjg); |
| | | strings.add(jgdw); |
| | | strings.add(fwz); |
| | | lists.add(strings); |
| | | } |
| | | if (!lists.isEmpty()) { |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("data",lists); |
| | | map.put("jyys",hashSet); |
| | | data.put(xmmc, map); |
| | | } |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | /** |
| | | * 生成PDF模版以及用户信息部分 |
| | | * @param tjOrder |
| | | * @param reportTemplate |
| | | */ |
| | | public HashMap<String ,Object> makePDFInfo(TjOrder tjOrder,TjCustomer tjCustomer,TjReportTemplate reportTemplate){ |
| | | String tjNumber = tjOrder.getTjNumber(); |
| | | String template = reportTemplate.getTemplate(); |
| | | LambdaQueryWrapper<DictComp> wq111 = new LambdaQueryWrapper<>(); |
| | | wq111.eq(DictComp::getDrugManufacturerId, tjOrder.getFirmId()); |
| | | DictComp dictComp = dictCompService.getOne(wq111); |
| | | LambdaQueryWrapper<TjOrderDetail> wq2 = new LambdaQueryWrapper<>(); |
| | | wq2.eq(TjOrderDetail::getOrderId, tjOrder.getOrderId()); |
| | | //20230306判断该项目是否退费/缴费 |
| | | wq2.isNotNull(TjOrderDetail::getFlowingWaterId); |
| | | //20230323判断该项目是否弃检/未检 |
| | | // wq2.eq(TjOrderDetail::getTjStatus,1); |
| | | List<TjOrderDetail> list = tjOrderDetailService.list(wq2); |
| | | for (TjOrderDetail tjOrderDetail : list) { |
| | | TjProject tjProject = projectService.selectTjProjectByProId(tjOrderDetail.getProId()); |
| | | tjOrderDetail.setProject(tjProject); |
| | | } |
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | | PdfReader reader = null; |
| | | PdfStamper pdfStamper = null; |
| | | try { |
| | | reader = new PdfReader(new ByteArrayInputStream(Base64.getDecoder().decode(template))); |
| | | pdfStamper = new PdfStamper(reader, byteArrayOutputStream); |
| | | // 获取pdf表单 |
| | | AcroFields acroFields = pdfStamper.getAcroFields(); |
| | | BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); |
| | | acroFields.addSubstitutionFont(bf); |
| | | HashMap<String, Object> data = new HashMap<>(); |
| | | // 设置用户信息 |
| | | setUserInfo(tjNumber, tjOrder, tjCustomer, data); |
| | | //异常项目 |
| | | if (dictComp == null) { |
| | | data.put("work", "无"); |
| | | } else { |
| | | data.put("work", dictComp.getCnName()); |
| | | } |
| | | //封面页下面的总检建议显示 |
| | | if (tjOrder.getCheckAdvice() == null) { |
| | | data.put("remark", "无"); |
| | | } else { |
| | | data.put("remark", tjOrder.getCheckAdvice()); |
| | | } |
| | | //封面页下面的总检建议显示 |
| | | if (tjOrder.getCheckDoctor() == null) { |
| | | data.put("docname", "无"); |
| | | } else { |
| | | data.put("docname", tjOrder.getCheckDoctor()); |
| | | } |
| | | //拼接重大阳性结果 |
| | | StringBuffer str = new StringBuffer(); |
| | | str.append("【重大阳性项目】\n"); |
| | | LambdaQueryWrapper<TjBigPositive> bigPositiveLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | bigPositiveLambdaQueryWrapper.eq(TjBigPositive::getTjNumber, tjNumber); |
| | | List<TjBigPositive> list1 = tjBigPositiveService.list(bigPositiveLambdaQueryWrapper); |
| | | if (list1 != null && list1.size() > 0) { |
| | | for (int i = 0; i < list1.size(); i++) { |
| | | str.append((i + 1) + "、" + list1.get(i).getProName() + ";\n"); |
| | | } |
| | | } else { |
| | | str.append(" 无;\n"); |
| | | } |
| | | //拼接异常项目 |
| | | str.append("【异常情况项目】\n"); |
| | | if (list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (list.get(i).getExceptionDesc() == 1) { |
| | | str.append((i + 1) + "、" + projectService.getById(list.get(i).getProId()).getProName() + ";\n"); |
| | | } |
| | | } |
| | | } else { |
| | | str.append(" 无;\n"); |
| | | } |
| | | //异常项目 |
| | | data.put("yichang", str.toString()); |
| | | // 遍历data 给pdf表单表格赋值 |
| | | for (String key : data.keySet()) { |
| | | acroFields.setField(key, data.get(key).toString()); |
| | | } |
| | | //设置为无法编辑 |
| | | pdfStamper.setFormFlattening(true); |
| | | pdfStamper.close(); |
| | | reader.close(); |
| | | // 将修改后的PDF内容写入 |
| | | byte[] bytes = byteArrayOutputStream.toByteArray(); |
| | | // 创建新的PDF文档 |
| | | Document document = new Document(PageSize.A4); |
| | | ByteArrayOutputStream finalOutPut = new ByteArrayOutputStream(); |
| | | PdfCopy copy = new PdfCopy(document, finalOutPut); |
| | | document.open(); |
| | | reader = new PdfReader(bytes); |
| | | int numberOfPages = reader.getNumberOfPages(); |
| | | for (int i = 1; i <= numberOfPages; i++) { |
| | | PdfImportedPage page = copy.getImportedPage(reader, i); |
| | | copy.addPage(page); |
| | | } |
| | | // 添加详情页 |
| | | document.newPage(); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("document",document); |
| | | map.put("copy",copy); |
| | | map.put("stream",finalOutPut); |
| | | return map; |
| | | } catch (IOException | DocumentException e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public Boolean makePDF(String cardId, JSONArray jsonArray,TjOrder tjOrder,TjReportTemplate reportTemplate) { |
| | | String tjNumber = tjOrder.getTjNumber(); |
| | | String template = reportTemplate.getTemplate(); |
| | |
| | | wq1.eq(TjCustomer::getCusId, tjOrder.getUserId()); |
| | | TjCustomer tjCustomer = tjCustomerService.getOne(wq1); |
| | | Long userId = tjCustomer.getCusId(); |
| | | LambdaQueryWrapper<DictComp> wq111 = new LambdaQueryWrapper<>(); |
| | | wq111.eq(DictComp::getDrugManufacturerId, tjOrder.getFirmId()); |
| | | DictComp dictComp = dictCompService.getOne(wq111); |
| | | LambdaQueryWrapper<TjOrderDetail> wq2 = new LambdaQueryWrapper<>(); |
| | | wq2.eq(TjOrderDetail::getOrderId, tjOrder.getOrderId()); |
| | | //20230306判断该项目是否退费/缴费 |
| | | wq2.isNotNull(TjOrderDetail::getFlowingWaterId); |
| | | //20230323判断该项目是否弃检/未检 |
| | | // wq2.eq(TjOrderDetail::getTjStatus,1); |
| | | List<TjOrderDetail> list = tjOrderDetailService.list(wq2); |
| | | for (TjOrderDetail tjOrderDetail : list) { |
| | | TjProject tjProject = projectService.selectTjProjectByProId(tjOrderDetail.getProId()); |
| | | tjOrderDetail.setProject(tjProject); |
| | | } |
| | | // 生成pdf |
| | | try { |
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | |
| | | // 设置用户信息 |
| | | setUserInfo(tjNumber, tjOrder, tjCustomer, data); |
| | | //异常项目 |
| | | if (dictComp == null) { |
| | | data.put("work", "无"); |
| | | } else { |
| | | data.put("work", dictComp.getCnName()); |
| | | } |
| | | //封面页下面的总检建议显示 |
| | | if (tjOrder.getCheckAdvice() == null) { |
| | | data.put("remark", "无"); |
| | | } else { |
| | | data.put("remark", tjOrder.getCheckAdvice()); |
| | | } |
| | | //封面页下面的总检建议显示 |
| | | if (tjOrder.getCheckDoctor() == null) { |
| | | data.put("docname", "无"); |
| | | } else { |
| | | data.put("docname", tjOrder.getCheckDoctor()); |
| | | } |
| | | //拼接重大阳性结果 |
| | | StringBuffer str = new StringBuffer(); |
| | | str.append("【重大阳性项目】\n"); |
| | | LambdaQueryWrapper<TjBigPositive> bigPositiveLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | bigPositiveLambdaQueryWrapper.eq(TjBigPositive::getTjNumber, tjNumber); |
| | | List<TjBigPositive> list1 = tjBigPositiveService.list(bigPositiveLambdaQueryWrapper); |
| | | if (list1 != null && list1.size() > 0) { |
| | | for (int i = 0; i < list1.size(); i++) { |
| | | str.append((i + 1) + "、" + list1.get(i).getProName() + ";\n"); |
| | | } |
| | | } else { |
| | | str.append(" 无;\n"); |
| | | } |
| | | //拼接异常项目 |
| | | str.append("【异常情况项目】\n"); |
| | | if (list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (list.get(i).getExceptionDesc() == 1) { |
| | | str.append((i + 1) + "、" + projectService.getById(list.get(i).getProId()).getProName() + ";\n"); |
| | | } |
| | | } |
| | | } else { |
| | | str.append(" 无;\n"); |
| | | } |
| | | |
| | | //异常项目 |
| | | data.put("yichang", str.toString()); |
| | | // 遍历data 给pdf表单表格赋值 |
| | | for (String key : data.keySet()) { |
| | | acroFields.setField(key, data.get(key).toString()); |
| | |
| | | PdfWriter pdfWriter = PdfWriter.getInstance(document1, byteArrayOutputStream1); |
| | | document1.setMargins(70, 70, 40, 40); |
| | | document1.open(); |
| | | // 非化验项目报告 |
| | | Map<TjOrderRemark, List<TjPdfVO>> printReport = new HashMap<>(); |
| | | notHuaYanData(tjNumber, printReport,tjOrder,tjCustomer); |
| | | for (Map.Entry<TjOrderRemark, List<TjPdfVO>> entry : printReport.entrySet()) { |
| | | List<TjPdfVO> value = entry.getValue(); |
| | | LambdaQueryWrapper<TjProject> wqqq = new LambdaQueryWrapper<>(); |
| | | wqqq.eq(TjProject::getProId, entry.getKey().getProId()); |
| | | TjProject one11 = projectService.getOne(wqqq); |
| | | //判断该项目是否需要打印报告 |
| | | if (null != one11 && "N".equals(one11.getNeedReport())) { |
| | | continue; |
| | | } |
| | | String titleName = null; |
| | | if (null != one11 && "1".equals(one11.getResultType())) { |
| | | titleName = one11.getProName(); |
| | | // TODO 单位 |
| | | // 设置标题字体样式 |
| | | Font titleFonts = PdfUtils.setFont(9); |
| | | Paragraph paragraph = PdfUtils.setParagraph(titleFonts, titleName); |
| | | String[] titles = {"体检项目", "体检结果","单位"}; |
| | | // 获取列表数据 |
| | | //设置表头字体样式 |
| | | Font headFont = PdfUtils.setFont(9); |
| | | // 设置正文字体样式:12号 |
| | | Font textFont = PdfUtils.setFont(9); |
| | | //创建表格 将表头字体和正文字体放进去 |
| | | PdfPTable table = PdfUtils.setTable2(headFont, textFont, titles, value); |
| | | document1.add(paragraph); |
| | | document1.add(table); |
| | | //判断备注是否为空 空不能显示null |
| | | if (entry.getKey().getRemark() == null) { |
| | | entry.getKey().setRemark(""); |
| | | } |
| | | String remark = "备注:" + entry.getKey().getRemark(); |
| | | if (entry.getKey().getRemark().length() > 50) { |
| | | int j = 0; |
| | | for (int i = 0; i < remark.length() / 50; i++) { |
| | | String substring = remark.substring(j, j + 50); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | j = j + 50; |
| | | } |
| | | if (remark.length() % 50 != 0) { |
| | | String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | } |
| | | } else { |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark); |
| | | document1.add(pp); |
| | | } |
| | | //判断主检医师是否为空 空不能显示null |
| | | if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) { |
| | | //主检医师 |
| | | String doctorName = "主检医师:" + userService.getById(entry.getKey().getDoctorName()).getNickName(); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } else { |
| | | String doctorName = "主检医师:" + "无"; |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } else { |
| | | if (null != one11) { |
| | | titleName = one11.getProName(); |
| | | } else { |
| | | titleName = entry.getKey().getProName(); |
| | | } |
| | | // 设置标题字体样式 |
| | | Font titleFonts = PdfUtils.setFont(9); |
| | | Paragraph paragraph = PdfUtils.setParagraph(titleFonts, titleName); |
| | | String[] titles = {"体检项目", "体检结果", "单位", "参考范围"}; |
| | | // 获取列表数据 |
| | | //设置表头字体样式 |
| | | Font headFont = PdfUtils.setFont(9); |
| | | // 设置正文字体样式:12号 |
| | | Font textFont = PdfUtils.setFont(9); |
| | | //创建表格 将表头字体和正文字体放进去 |
| | | PdfPTable table = PdfUtils.setTable(headFont, textFont, titles, value); |
| | | document1.add(paragraph); |
| | | document1.add(table); |
| | | //判断备注是否为空 空不能显示null |
| | | if (entry.getKey().getRemark() == null) { |
| | | entry.getKey().setRemark(""); |
| | | } |
| | | String remark = "备注:" + entry.getKey().getRemark(); |
| | | if (entry.getKey().getRemark().length() > 50) { |
| | | int j = 0; |
| | | for (int i = 0; i < remark.length() / 50; i++) { |
| | | String substring = remark.substring(j, j + 50); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | j = j + 50; |
| | | } |
| | | if (remark.length() % 50 != 0) { |
| | | String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | } |
| | | } else { |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark); |
| | | document1.add(pp); |
| | | } |
| | | //判断主检医师是否为空 空不能显示null |
| | | if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) { |
| | | //主检医师 |
| | | String doctorName = "主检医师:" + userService.getById(entry.getKey().getDoctorName()).getNickName(); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } else { |
| | | String doctorName = "主检医师:" + "无"; |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } |
| | | } |
| | | List<ByteArrayOutputStream> jianchas = new ArrayList<>(); |
| | | for (Object o : jsonArray) { |
| | | JSONObject jsonObject = (JSONObject) o; |
| | |
| | | titleName = reportInfo.getStr("JYXMMC").trim(); |
| | | } |
| | | JSONArray reportDetails = jsonObject.getJSONArray("检验结果记录"); |
| | | ArrayList<TjPdfVO> list = new ArrayList<>(); |
| | | ArrayList<TjPdfVO> listPdf = new ArrayList<>(); |
| | | String[] titles = null; |
| | | float[] titlesWidth = null; |
| | | // 结果信息 |
| | |
| | | tjPdfVO.setProResult(detail.getStr("JCZBJG")); |
| | | tjPdfVO.setVal1(detail.getStr("JLDW")); |
| | | tjPdfVO.setVal2(detail.getStr("CKZFW")); |
| | | list.add(tjPdfVO); |
| | | listPdf.add(tjPdfVO); |
| | | } |
| | | titles = new String[]{"体检项目", "体检结果", "单位", "参考范围"}; |
| | | titlesWidth = new float[]{120, 120, 120, 120}; |
| | | addTable(document1, titleName, titles, titlesWidth, list); |
| | | addTable(document1, titleName, titles, titlesWidth, listPdf); |
| | | // 主检医师 |
| | | String bgysqm = reportInfo.getStr("BGYSQM"); |
| | | String doctorName = "主检医师:" + bgysqm; |
| | |
| | | // 微生物报告记录信息 |
| | | JSONArray labgermrepInfos = jsonObject.getJSONArray("微生物报告记录"); |
| | | if (labgermrepInfos != null && labgermrepInfos.size() > 0) { |
| | | list = new ArrayList<>(); |
| | | listPdf = new ArrayList<>(); |
| | | for (Object info : labgermrepInfos) { |
| | | JSONObject object = (JSONObject) info; |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | | tjPdfVO.setProName(object.getStr("XJMC")); |
| | | tjPdfVO.setProResult(object.getStr("JCJG")); |
| | | list.add(tjPdfVO); |
| | | listPdf.add(tjPdfVO); |
| | | } |
| | | titles = new String[]{"体检项目", "体检结果"}; |
| | | titlesWidth = new float[]{120, 120}; |
| | | addTable(document1, titleName, titles, titlesWidth, list); |
| | | addTable(document1, titleName, titles, titlesWidth, listPdf); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | |
| | | // 微生物药敏信息 |
| | | JSONArray labgermdetailinfos = jsonObject.getJSONArray("微生物药敏信息"); |
| | | if (labgermdetailinfos != null && labgermdetailinfos.size() > 0) { |
| | | list = new ArrayList<>(); |
| | | listPdf = new ArrayList<>(); |
| | | for (Object info : labgermdetailinfos) { |
| | | JSONObject object = (JSONObject) info; |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | |
| | | tjPdfVO.setVal1(object.getStr("ZPHYL")); |
| | | tjPdfVO.setVal2(object.getStr("YJND")); |
| | | tjPdfVO.setVal3(object.getStr("YJHZJ")); |
| | | list.add(tjPdfVO); |
| | | listPdf.add(tjPdfVO); |
| | | } |
| | | titles = new String[]{"药敏名称", "检查结果", "纸片含药量", "抑菌浓度", "抑菌环直径"}; |
| | | titlesWidth = new float[]{90, 90, 90, 90, 90}; |
| | | addTable(document1, titleName, titles, titlesWidth, list); |
| | | addTable(document1, titleName, titles, titlesWidth, listPdf); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | |
| | | // 危急值信息 |
| | | JSONArray laburgentinfos = jsonObject.getJSONArray("危机值信息"); |
| | | if (laburgentinfos != null && laburgentinfos.size() > 0) { |
| | | list = new ArrayList<>(); |
| | | listPdf = new ArrayList<>(); |
| | | for (Object info : laburgentinfos) { |
| | | JSONObject object = (JSONObject) info; |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | |
| | | tjPdfVO.setProResult(object.getStr("jg")); |
| | | tjPdfVO.setVal1(object.getStr("clfs")); |
| | | tjPdfVO.setVal2(object.getStr("bgcljg")); |
| | | list.add(tjPdfVO); |
| | | listPdf.add(tjPdfVO); |
| | | } |
| | | titles = new String[]{"指标名称", "危急值结果", "处理方式", "处理意见"}; |
| | | titlesWidth = new float[]{120, 120, 120, 120}; |
| | | addTable(document1, titleName, titles, titlesWidth, list); |
| | | addTable(document1, titleName, titles, titlesWidth, listPdf); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | |
| | | document.close(); |
| | | copy.close(); |
| | | reader.close(); |
| | | String outputFileName1 = userId + tjNumber + tjCustomer.getCusName() + "_报告.pdf"; |
| | | // TODO 文件配置 |
| | | // String outputPath1 = "/Users/chacca/开发相关/代码/"; |
| | | String outputPath1 = value+"\\"; |
| | | String outputFileName1 = userId + tjNumber + tjCustomer.getCusName() + "_报告.pdf"; |
| | | File file = new File(outputPath1 + outputFileName1); |
| | | BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); |
| | | outputStream.write(finalOutPut.toByteArray()); |
| | |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | // 组合非化验项目报告数据 |
| | | private void notHuaYanData(String tjNumber, Map<TjOrderRemark, List<TjPdfVO>> printReport,TjOrder one,TjCustomer customer) { |
| | | LambdaQueryWrapper<TjOrderRemark> wqq = new LambdaQueryWrapper<>(); |
| | | wqq.eq(TjOrderRemark::getTjNumber, tjNumber); |
| | | wqq.ne(TjOrderRemark::getDeptId, "241"); |
| | | wqq.in(TjOrderRemark::getDeptId, "269", "270", "253", "254", "255", "257", "251", "271"); |
| | | wqq.notIn(TjOrderRemark::getProId, projectService.getNneedReprotProId()); |
| | | List<TjOrderRemark> tjOrderRemarks = tjOrderRemarkService.list(wqq); |
| | | for (TjOrderRemark tjOrderRemark : tjOrderRemarks) { |
| | | printReport.put(tjOrderRemark, null); |
| | | } |
| | | for (Map.Entry<TjOrderRemark, List<TjPdfVO>> entry : printReport.entrySet()) { |
| | | List<TjPdfVO> tjPdfVOS = new ArrayList<>(); |
| | | List<TjOrderDetail> tjOrderDetails = tjOrderDetailService.getDetailByOrderIdAndParId(one.getOrderId(), entry.getKey().getProId()); |
| | | for (TjOrderDetail tjOrderDetail : tjOrderDetails) { |
| | | TjProject tjProject = projectService.getById(tjOrderDetail.getProId()); |
| | | if (null != tjProject) { |
| | | tjOrderDetail.setProject(tjProject); |
| | | } |
| | | if (tjOrderDetail.getProject().getProParentId().equals(entry.getKey().getProId())) { |
| | | LambdaQueryWrapper<TjStandard> wq6 = new LambdaQueryWrapper<>(); |
| | | wq6.eq(TjStandard::getProId, tjOrderDetail.getProId()); |
| | | List<TjStandard> list2 = tjStandardService.list(wq6); |
| | | if (list2.size() == 0) { |
| | | TjStandard s = new TjStandard(); |
| | | s.setCompany(" "); |
| | | s.setTjStandardLtValue(" "); |
| | | s.setTjStandardGtValue(" "); |
| | | tjOrderDetail.setStandard(s); |
| | | } else if (list2.size() == 1) { |
| | | tjOrderDetail.setStandard(list2.get(0)); |
| | | } else { |
| | | Long cusSex = customer.getCusSex(); |
| | | Date cusBrithday = customer.getCusBrithday(); |
| | | int age = DateUtil.ageOfNow(cusBrithday); |
| | | for (TjStandard tjStandard : list2) { |
| | | LambdaQueryWrapper<TjStandard> wq8 = new LambdaQueryWrapper<>(); |
| | | if (tjStandard.getTjSex() != null) { |
| | | wq8.eq(TjStandard::getTjSex, cusSex); |
| | | } |
| | | if (tjStandard.getTjType() != null) { |
| | | wq8.eq(TjStandard::getTjType, StringUtils.getAgeType(age)); |
| | | } |
| | | TjStandard standard = tjStandardService.getOne(wq8); |
| | | tjOrderDetail.setStandard(standard); |
| | | } |
| | | } |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | | tjPdfVO.setProName(tjOrderDetail.getProject().getProName()); |
| | | tjPdfVO.setProResult(tjOrderDetail.getProResult()); |
| | | tjPdfVO.setExc(tjOrderDetail.getExceptionDesc()); |
| | | if (tjOrderDetail.getStandard() != null) { |
| | | //单位 |
| | | if (tjOrderDetail.getStandard().getCompany() == null) { |
| | | tjPdfVO.setCompany(" "); |
| | | } else { |
| | | tjPdfVO.setCompany(tjOrderDetail.getStandard().getCompany()); |
| | | } |
| | | // TODO 设置单位 |
| | | //最大值和最小值 |
| | | String tjStandardGtValue = tjOrderDetail.getStandard().getTjStandardGtValue(); |
| | | String tjStandardLtValue = tjOrderDetail.getStandard().getTjStandardLtValue(); |
| | | if (tjStandardGtValue == null) { |
| | | tjStandardGtValue = " "; |
| | | } |
| | | if (tjStandardLtValue == null) { |
| | | tjStandardLtValue = " "; |
| | | } |
| | | tjPdfVO.setStandardValue(tjStandardLtValue + "-" + tjStandardGtValue); |
| | | } |
| | | tjPdfVOS.add(tjPdfVO); |
| | | } |
| | | } |
| | | printReport.put(entry.getKey(), tjPdfVOS); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | data.put("num3", 4); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param document |
| | | * @param titleName |
| | | * @param titles |
| | | * @param titlesWidth |
| | | * @param list |
| | | * @throws DocumentException |
| | | * @deprecated 数据从数据库查有具体的实体类 |
| | | */ |
| | | @Deprecated |
| | | private static void addTable(Document document, String titleName, String[] titles, float[] titlesWidth, ArrayList<TjPdfVO> list) throws DocumentException { |
| | | Font titleFont = PdfUtils.setFont(9); |
| | | Paragraph paragraph = new Paragraph(titleName, titleFont); |
| | | // 设置文字居中 |
| | | paragraph.setAlignment(Element.ALIGN_LEFT); |
| | | // 行间距 |
| | | // paragraph.setLeading(5f); |
| | | paragraph.setLeading(5f); |
| | | // 设置段落上空白 |
| | | paragraph.setSpacingBefore(10f); |
| | | // 设置段落下空白 |
| | |
| | | PdfPTable table = new PdfPTable(titlesWidth); |
| | | table.setTotalWidth(PageSize.A4.getWidth() - 100); // 设置表格总宽度 |
| | | table.setLockedWidth(true); // 锁定表格宽度 |
| | | table.setHorizontalAlignment(Element.ALIGN_LEFT); |
| | | table.getDefaultCell().setBorder(0); |
| | | table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); |
| | | for (String title : titles) { |
| | | PdfPCell cell = new PdfPCell(new Paragraph(title, headFont)); |
| | | cell.setVerticalAlignment(Element.ALIGN_MIDDLE); |
| | | cell.setHorizontalAlignment(Element.ALIGN_LEFT); |
| | | cell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框 |
| | | table.addCell(cell); |
| | | } |
| | |
| | | } else { |
| | | elements = new Paragraph(value, textFont); |
| | | } |
| | | PdfPCell nameCell = new PdfPCell(elements); |
| | | PdfPCell nameCell = new PdfPCell(); |
| | | nameCell.setVerticalAlignment(Element.ALIGN_MIDDLE); |
| | | nameCell.setHorizontalAlignment(Element.ALIGN_LEFT); |
| | | nameCell.setPhrase(elements); |
| | | nameCell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框 |
| | | table.addCell(nameCell); |
| | | } |
| | |
| | | document.add(table); |
| | | } |
| | | |
| | | private static void addJianYanTable(Document document, String titleName, String[] titles, float[] titlesWidth, ArrayList<List<String >> lists) throws DocumentException { |
| | | Font titleFont = PdfUtils.setFont(9); |
| | | Paragraph paragraph = new Paragraph(titleName, titleFont); |
| | | // 设置文字居中 |
| | | paragraph.setAlignment(Element.ALIGN_LEFT); |
| | | // 行间距 |
| | | paragraph.setLeading(5f); |
| | | // 设置段落上空白 |
| | | paragraph.setSpacingBefore(10f); |
| | | // 设置段落下空白 |
| | | paragraph.setSpacingAfter(10f); |
| | | document.add(paragraph); |
| | | // 创建一个表格并添加到文档 |
| | | Font headFont = PdfUtils.setFont(9); |
| | | Font textFont = PdfUtils.setFont(9); |
| | | PdfPTable table = new PdfPTable(titlesWidth); |
| | | table.setTotalWidth(PageSize.A4.getWidth() - 100); // 设置表格总宽度 |
| | | table.setLockedWidth(true); // 锁定表格宽度 |
| | | table.setHorizontalAlignment(Element.ALIGN_LEFT); |
| | | table.getDefaultCell().setBorder(0); |
| | | table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); |
| | | for (String title : titles) { |
| | | PdfPCell cell = new PdfPCell(new Paragraph(title, headFont)); |
| | | cell.setVerticalAlignment(Element.ALIGN_MIDDLE); |
| | | cell.setHorizontalAlignment(Element.ALIGN_LEFT); |
| | | cell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框 |
| | | table.addCell(cell); |
| | | } |
| | | for (List<String> list : lists) { |
| | | for (String s : list) { |
| | | PdfPCell nameCell = new PdfPCell(); |
| | | nameCell.setVerticalAlignment(Element.ALIGN_MIDDLE); |
| | | nameCell.setHorizontalAlignment(Element.ALIGN_LEFT); |
| | | nameCell.setPhrase(new Paragraph(s, textFont)); |
| | | nameCell.setBorder(Rectangle.NO_BORDER); // 移除单元格边框 |
| | | table.addCell(nameCell); |
| | | } |
| | | } |
| | | document.add(table); |
| | | } |
| | | |
| | | /** |
| | | * 创建检查pdf |
| | | * @param xm |