From 89e13d18f95a42ac75f46845165c7fbbc665d09a Mon Sep 17 00:00:00 2001 From: 赵文轩 <1652863494@qq.com> Date: 星期三, 12 六月 2024 09:03:00 +0800 Subject: [PATCH] 生成pdf未完成 --- ltkj-admin/src/main/java/com/ltkj/web/controller/his/TestGetController.java | 329 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 320 insertions(+), 9 deletions(-) diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/his/TestGetController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/his/TestGetController.java index dce6811..46afd11 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/his/TestGetController.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/his/TestGetController.java @@ -1,9 +1,25 @@ package com.ltkj.web.controller.his; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.itextpdf.text.*; +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.utils.DateUtils; +import com.ltkj.common.utils.StringUtils; +import com.ltkj.framework.config.MatchUtils; +import com.ltkj.hosp.domain.*; +import com.ltkj.hosp.service.*; +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 org.springframework.web.bind.annotation.PostMapping; @@ -11,9 +27,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.HashMap; +import java.io.*; +import java.util.*; import java.util.List; -import java.util.Map; +import java.util.stream.Collectors; @Slf4j @RestController @@ -21,6 +38,32 @@ public class TestGetController { @Autowired private HisApiGetMethodService apiGetMethodService; + @Autowired + private ITjOrderService tjOrderService; + @Autowired + private ISysDictDataService dictDataService; + @Autowired + private ITjReportTemplateService reportTemplateService; + @Autowired + private ITjCustomerService tjCustomerService; + @Autowired + private IDictCompService dictCompService; + @Autowired + private ITjProjectService tjProjectService; + @Autowired + private ITjOrderDetailService tjOrderDetailService; + @Autowired + private ITjReportService tjReportService; + @Autowired + private ITjBigPositiveService tjBigPositiveService; + @Autowired + private ITjProjectService projectService; + @Autowired + private ISysUserService userService; + @Autowired + private ITjOrderRemarkService tjOrderRemarkService; + @Autowired + private ITjStandardService tjStandardService; @PostMapping("test") public AjaxResult test(@RequestBody String json){ @@ -28,7 +71,7 @@ JSONObject jsonObject = JSONUtil.parseObj(json); HashMap<String, Object> hashMap = new HashMap<>(); // 2.4.2 ----- 2.4.7 - // 鐢卞墠闈㈢殑鎺ュ彛鐢熸垚 20240604000160 + // 鐢卞墠闈㈢殑鎺ュ彛鐢熸垚 20240604000160 hashMap.put("his_registration_id",jsonObject.getStr("his_registration_id")); hashMap.put("ksbm","0101"); // 鐢卞墠闈㈢殑鎺ュ彛鐢熸垚 20220427000227 @@ -79,6 +122,15 @@ return data; } + + // hisID + /* + 2024-06-01 08:00:00 2024-06-11 19:00:00 + * 2024013998 + * 2024014026 + * 2024014066 + * 2024014112 + * */ @PostMapping("test_all") public AjaxResult testALL(@RequestBody String json){ // pdf淇℃伅闆嗗悎 @@ -95,7 +147,7 @@ String mzorzy = params.get("mzorzy").toString(); String cardtype = params.get("cardtype").toString(); String ksbm = params.get("ksbm").toString(); - String pationid = null; + String pationid = ""; // 鑾峰彇妫�鏌ョ敵璇蜂俊鎭� // AjaxResult getexamapplyinfo = apiGetMethodService.getHISDataNew("Getexamapplyinfo", params); List<Map<String ,Object>> list; @@ -141,30 +193,289 @@ params.put("page",1); AjaxResult getlabreportinfo = apiGetMethodService.getHISDataNew("Getlabreportinfo", params); list = makePDFInfo(pdfInfoMap,getlabreportinfo,"鑾峰彇妫�楠屾姤鍛婅褰曚俊鎭�"); + JSONArray jsonArray = JSONUtil.createArray(); if (list != null){ params.clear(); for (Map<String, Object> stringObjectMap : list) { + JSONObject obj = JSONUtil.createObj(); + obj.putOpt("鎶ュ憡璁板綍",stringObjectMap); String jybgid = stringObjectMap.get("JYBGID").toString(); params.put("jybgid",jybgid); // 鑾峰彇妫�楠岀粨鏋滆褰曚俊鎭� AjaxResult getlabdetailinfo = apiGetMethodService.getHISDataNew("Getlabdetailinfo", params); - makePDFInfo(pdfInfoMap,getlabdetailinfo,"妫�楠岀粨鏋滆褰�"); + if (Integer.parseInt(getlabdetailinfo.get("code").toString()) == 200) { + List<Map<String, Object>> data = (List<Map<String, Object>>) getlabdetailinfo.get("data"); + obj.putOpt("妫�楠岀粨鏋滆褰�", data); + } // 鑾峰彇寰敓鐗╂姤鍛婅褰曚俊鎭� AjaxResult getlabgermrepinfo = apiGetMethodService.getHISDataNew("Getlabgermrepinfo", params); - makePDFInfo(pdfInfoMap,getlabgermrepinfo,"寰敓鐗╂姤鍛婅褰�"); + if (Integer.parseInt(getlabgermrepinfo.get("code").toString()) == 200) { + List<Map<String, Object>> data = (List<Map<String, Object>>) getlabgermrepinfo.get("data"); + obj.putOpt("寰敓鐗╂姤鍛婅褰�", data); + } // 鑾峰彇寰敓鐗╄嵂鏁忎俊鎭� AjaxResult getlabgermdetailinfo = apiGetMethodService.getHISDataNew("Getlabgermdetailinfo", params); - makePDFInfo(pdfInfoMap,getlabgermdetailinfo,"寰敓鐗╄嵂鏁忎俊鎭�"); + if (Integer.parseInt(getlabgermdetailinfo.get("code").toString()) == 200) { + List<Map<String, Object>> data = (List<Map<String, Object>>) getlabgermdetailinfo.get("data"); + obj.putOpt("寰敓鐗╄嵂鏁忎俊鎭�", data); + } // 鑾峰彇鍗辨�ュ�间俊鎭� AjaxResult getlaburgentinfo = apiGetMethodService.getHISDataNew("Getlaburgentinfo", params); - makePDFInfo(pdfInfoMap,getlaburgentinfo,"鍗辨満鍊间俊鎭�"); + if (Integer.parseInt(getlaburgentinfo.get("code").toString()) == 200) { + List<Map<String, Object>> data = (List<Map<String, Object>>) getlaburgentinfo.get("data"); + obj.putOpt("鍗辨満鍊间俊鎭�", data); + } + jsonArray.put(obj); } - System.out.println(JSONUtil.toJsonStr(pdfInfoMap)); +// System.out.println(JSONUtil.toJsonStr(pdfInfoMap)); + System.out.println(JSONUtil.toJsonStr(jsonArray)); // 杩斿洖涓枃瀛楁鏇挎崲 // {"鑾峰彇妫�楠屾姤鍛婅褰曚俊鎭�":[{"搴婁綅鍙�":"3","鎶ュ憡绫诲埆浠g爜":"null","闂ㄨ瘖浣忛櫌鏍囧織":"1","鐢宠鏃ユ湡鏃堕棿":"2024-05-22T10:38:00","瑗垮尰璇婃柇浠g爜":"","鐥呮埧鍙�":"","妫�楠屾姤鍛婂崟鍙�":"240522000899","鎶ュ憡鍗曠被鍒�":"寰敓鐗╂楠屾姤鍛婂崟","鎶ュ憡鍖荤敓浠g爜":"02172","闂ㄨ瘖鎬ヨ瘖鍙�":"0","鐢宠鍖荤敓濮撳悕":"琚佸皬娴�","妫�楠屾姤鍛� ID":"240522000899","鎮h�呭鍚�":"寮犳捣娑�","妗f淇濆瓨鏈烘瀯鍚嶇О":"娉惧窛鍘夸汉姘戝尰闄�","妗f淇濆瓨鏈烘瀯鍦板潃":"娉惧窛鍘夸汉姘戝尰闄�","鍖荤枟鏈烘瀯浠g爜":"43899007-X","涓汉鏍囪瘑鍙�":"20240522000046","鐢佃瘽鍙风爜":"15294040899","閲囨牱鏃ユ湡鏃堕棿":"2024-05-22T11:09:16.51","淇敼鏍囧織":"0","鎵撳嵃鏃ユ湡":"2024-06-03T10:28:28.743","鏂囦欢閾炬帴":"-","瀹℃牳浜哄憳濮撳悕":"鐜嬫儬鎯�","鐢宠鏃ユ湡":"2024-05-22T10:38:00","璁板綍鍖荤敓浠g爜":"02172","妫�楠岄」鐩悕绉�":"鏅�氱粏鑿屽煿鍏�+鑽晱(鐥�)","瀹℃牳浜哄憳浠g爜":"02172","鎮h�呯被鍨嬩唬鐮�":"1","鏍囨湰绫诲瀷":"鐥版恫","瀹℃牳浜哄憳濮撳悕":"鐜嬭姵","鏍囨湰鐘舵��":"宸查噰鏍�","鏍囨湰浠g爜":"null","妫�楠岄」鐩唬鐮�":"600","鎶ュ憡绉戝浠g爜":"0016","鎶ュ憡绉戝鍚嶇О":"鐢熷寲瀹�","妫�楠屾姤鍛婄粨鏋�":"宸插","妫�楠屽娉�":"-","鎶ュ憡鏃ユ湡":"2024-06-03T10:28:28.743","鎶ュ憡鍖荤敓濮撳悕":"鐜嬫儬鎯�","鐢宠鏈烘瀯鍚嶇О":"娉惧窛鍘夸汉姘戝尰闄�","璁板綍鍖荤敓濮撳悕":"鐜嬭姵","鐢宠鏈烘瀯浠g爜":"43899007-X","閫佹鏃堕棿":"2024-06-03T10:28:20.203","妗f淇濆瓨鏈烘瀯浠g爜":"43899007-X","琛屾暟":"1","骞撮緞":"82","鐢宠绉戝鍚嶇О":"鍐呬竷绉�","鏍囨湰缂栧彿":"2024060302","鐢宠绉戝浠g爜":"0072","鎮h�呯瀹ゅ悕绉�":"鍐呬竷绉�","妫�楠屾牱鏈紪鍙�":"yl2024052200000622","鎶ュ憡鍖荤敓浠g爜":"02188","鐢宠鍖荤敓浠g爜":"00123"},{"搴婁綅鍙�":"4","鎶ュ憡绫诲埆浠g爜":"null","闂ㄨ瘖浣忛櫌鏍囧織":"1","鐢宠鏃ユ湡鏃堕棿":"2024-06-02T09:56:00","瑗垮尰璇婃柇浠g爜":"","鐥呮埧鍙�":"","妫�楠屾姤鍛婂崟鍙�":"240602000236","鎶ュ憡鍗曠被鍒�":"寰敓鐗╂楠屾姤鍛婂崟","鎶ュ憡鍖荤敓浠g爜":"03089","闂ㄨ瘖鎬ヨ瘖鍙�":"0","鐢宠鍖荤敓濮撳悕":"钄鸿姵鑺�","妫�楠屾姤鍛� ID":"240602000236","鎮h�呭鍚�":"寮犳捣娑�","妗f淇濆瓨鏈烘瀯鍚嶇О":"娉惧窛鍘夸汉姘戝尰闄�","妗f淇濆瓨鏈烘瀯鍦板潃":"娉惧窛鍘夸汉姘戝尰闄�","鍖荤枟鏈烘瀯浠g爜":"43899007-X","涓汉鏍囪瘑鍙�":"20240522000046","鐢佃瘽鍙风爜":"15294040899","閲囨牱鏃ユ湡鏃堕棿":"2024-06-02T09:58:50","淇敼鏍囧織":"0","鎵撳嵃鏃ユ湡":"2024-06-03T08:34:15.843","鏂囦欢閾炬帴":"-","瀹℃牳浜哄憳濮撳悕":"椴佺孩濞�","鐢宠鏃ユ湡":"2024-06-02T09:56:00","璁板綍鍖荤敓浠g爜":"03089","妫�楠岄」鐩悕绉�":"鏅�氱粏鑿屽煿鍏�+鑽晱(鐥�)","瀹℃牳浜哄憳浠g爜":"03089","鎮h�呯被鍨嬩唬鐮�":"1","鏍囨湰绫诲瀷":"鐥版恫","瀹℃牳浜哄憳濮撳悕":"鐜嬭姵","鏍囨湰鐘舵��":"鏈噰鏍�","鏍囨湰浠g爜":"null","妫�楠岄」鐩唬鐮�":"600","鎶ュ憡绉戝浠g爜":"0016","鎶ュ憡绉戝鍚嶇О":"鐢熷寲瀹�","妫�楠屾姤鍛婄粨鏋�":"宸插","妫�楠屽娉�":"-","鎶ュ憡鏃ユ湡":"2024-06-03T08:34:15.843","鎶ュ憡鍖荤敓濮撳悕":"椴佺孩濞�","鐢宠鏈烘瀯鍚嶇О":"娉惧窛鍘夸汉姘戝尰闄�","璁板綍鍖荤敓濮撳悕":"鐜嬭姵","鐢宠鏈烘瀯浠g爜":"43899007-X","閫佹鏃堕棿":"2024-06-03T08:34:14.26","妗f淇濆瓨鏈烘瀯浠g爜":"43899007-X","琛屾暟":"2","骞撮緞":"82","鐢宠绉戝鍚嶇О":"鍐呬竷绉�","鏍囨湰缂栧彿":"2024060301","鐢宠绉戝浠g爜":"0072","鎮h�呯瀹ゅ悕绉�":"鍐呬竷绉�","妫�楠屾牱鏈紪鍙�":"yl2024060200000185","鎶ュ憡鍖荤敓浠g爜":"02188","鐢宠鍖荤敓浠g爜":"00337"}]} + // TODO 鐢熸垚PDF 灞曠ず淇℃伅 PDF姣忛」淇℃伅涓嶆崲鏂伴〉 鐩存帴杩炵画鐢熸垚 鍚庢湡pdf浼氭湁鎺掑簭 姣斿鍏堣緭鍑哄績鐢靛浘鍐嶆槸琛�甯歌绛夌瓑... + // TODO 涓嶅啀浣跨敤makePDFInfo鏂规硶 + // 鐢ㄦ埛淇℃伅 + // select o.*,c.* from tj_order o,tj_customer c where o.user_id = c.cus_id and o.card_id = 'hisID'; +// makePDF(hisRegistrationId); + makePDF(hisRegistrationId,jsonArray); return AjaxResult.success(); }else { return AjaxResult.error("鏈幏鍙栧埌妫�楠屾姤鍛婅褰曚俊鎭�"); } } + + public AjaxResult makePDF(String cardId,JSONArray jsonArray){ + LambdaQueryWrapper<TjOrder> tjOrderLambdaQueryWrapper = new LambdaQueryWrapper<>(); + tjOrderLambdaQueryWrapper.eq(TjOrder::getCardId,cardId); + TjOrder tjOrder = tjOrderService.getOne(tjOrderLambdaQueryWrapper); + String tjNumber = tjOrder.getTjNumber(); + if (null != tjOrder){ + LambdaQueryWrapper<TjReportTemplate> tjReportTemplateLambdaQueryWrapper = new LambdaQueryWrapper<>(); + TjReportTemplate reportTemplate = null; + if (tjOrder.getTjCategory() != null) { + //鏌ヨ瀛楀吀 + LambdaQueryWrapper<SysDictData> wqq = new LambdaQueryWrapper<>(); + wqq.eq(SysDictData::getDictType, "dict_tjtype"); + wqq.eq(SysDictData::getDictValue, tjOrder.getTjCategory()); + SysDictData one = dictDataService.getOne(wqq); + if (one != null) { + //鏌ヨ瀛楀吀 + LambdaQueryWrapper<SysDictData> wqq1 = new LambdaQueryWrapper<>(); + wqq1.eq(SysDictData::getDictType, "report_template_type"); + wqq1.eq(SysDictData::getDictLabel, one.getDictLabel()); + SysDictData one1 = dictDataService.getOne(wqq1); + if (one1 != null) { + tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getFlag, one1.getDictValue()); + } else { + tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getFlag, 1); + } + } else { + tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getFlag, 1); + } + tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getOpen, 0); + reportTemplate = reportTemplateService.getOne(tjReportTemplateLambdaQueryWrapper); + } else { + tjReportTemplateLambdaQueryWrapper.eq(TjReportTemplate::getOpen, 0); + reportTemplate = reportTemplateService.list(tjReportTemplateLambdaQueryWrapper).get(2); + } + String template = reportTemplate.getTemplate(); + + // 鐢熸垚妯$増 + byte[] decodedBytes = Base64.getDecoder().decode(template); + try (FileOutputStream fos = new FileOutputStream("/Users/chacca/寮�鍙戠浉鍏�/浠g爜/template.pdf")) { + // 灏嗗瓧鑺傛暟缁勫啓鍏ユ枃浠� + fos.write(decodedBytes); + System.out.println("PDF file saved successfully."); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("Failed to save PDF file."); + } + + LambdaQueryWrapper<TjCustomer> wq1 = new LambdaQueryWrapper<>(); + wq1.eq(TjCustomer::getCusId, tjOrder.getUserId()); + TjCustomer tjCustomer = tjCustomerService.getOne(wq1); + Long userId = tjCustomer.getCusId(); + // 鐢熸垚pdf + try { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + PdfReader reader = new PdfReader(new ByteArrayInputStream(Base64.getDecoder().decode(template))); + PdfStamper 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); + //寮傚父椤圭洰 + // 閬嶅巻data 缁檖df琛ㄥ崟琛ㄦ牸璧嬪�� + for (String key : data.keySet()) { + acroFields.setField(key, data.get(key).toString()); + } + //璁剧疆涓烘棤娉曠紪杈� + pdfStamper.setFormFlattening(true); + pdfStamper.close(); + reader.close(); + // 灏嗕慨鏀瑰悗鐨凱DF鍐呭鍐欏叆 + 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(); + ByteArrayOutputStream byteArrayOutputStream1 = new ByteArrayOutputStream(); + Document document1 = new Document(PageSize.A4); + PdfWriter pdfWriter = PdfWriter.getInstance(document1, byteArrayOutputStream1); + document1.setMargins(70, 70, 40, 40); + document1.open(); + for (Object o : jsonArray) { + JSONObject jsonObject = (JSONObject) o; + JSONObject reportInfo = jsonObject.getJSONObject("鎶ュ憡璁板綍"); + String titleName = reportInfo.getStr("JYXMMC").trim(); + JSONArray reportDetails = jsonObject.getJSONArray("妫�楠岀粨鏋滆褰�"); + ArrayList<TjPdfVO> list = new ArrayList<>(); + for (Object reportDetail : reportDetails) { + JSONObject detail = (JSONObject) reportDetail; + TjPdfVO tjPdfVO = new TjPdfVO(); + tjPdfVO.setProName(detail.getStr("JCZBMC")); + tjPdfVO.setProResult(detail.getStr("JCZBJG")); + tjPdfVO.setCompany(detail.getStr("JLDW")); + tjPdfVO.setStandardValue(detail.getStr("CKZFW")); + list.add(tjPdfVO); + } + String[] titles = {"浣撴椤圭洰", "浣撴缁撴灉", "鍗曚綅", "鍙傝�冭寖鍥�"}; + float[] titlesWidth = {120, 120, 120, 120}; + addTable(document1,titleName,titles,titlesWidth,list); + // 涓绘鍖诲笀 + String bgysqm = reportInfo.getStr("BGYSQM"); + String doctorName = "涓绘鍖诲笀锛�"+bgysqm; + 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); + } + document1.close(); + pdfWriter.close(); + 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); + } + byteArrayOutputStream1.close(); + document.close(); + copy.close(); + String outputPath1 = "/Users/chacca/寮�鍙戠浉鍏�/浠g爜/"; + String outputFileName1 = userId + tjNumber + tjCustomer.getCusName() + "_鎶ュ憡.pdf"; + File file = new File(outputPath1 + outputFileName1); + BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); + outputStream.write(finalOutPut.toByteArray()); + outputStream.flush(); + outputStream.close(); + finalOutPut.close(); + reader.close(); + } catch (IOException | DocumentException e) { + throw new RuntimeException(e); + } + return AjaxResult.success(); + }else { + return AjaxResult.error("鏈煡璇㈠埌浣撴淇℃伅"); + } + } + + /** + * 璁剧疆鐢ㄦ埛淇℃伅 + * @param tjNumber + * @param tjOrder + * @param tjCustomer + * @param data + */ + private void setUserInfo(String tjNumber, TjOrder tjOrder, TjCustomer tjCustomer, Map<String, Object> data) { + //濉厖鎬у埆锛氬垽鏂敺濂� + Long cusSex = tjCustomer.getCusSex(); + String sex; + String name1; + String tjtype; + if (cusSex == 0) { + sex = "鐢�"; + name1 = tjCustomer.getCusName() + "鍏堢敓"; + } else { + sex = "濂�"; + name1 = tjCustomer.getCusName() + "濂冲+"; + } + data.put("name", tjCustomer.getCusName()); + data.put("cusId", tjCustomer.getCusId()); + data.put("name1", name1); + if ("1".equals(tjOrder.getTjType())) { + tjtype = "鍥㈤槦"; + data.put("tjtype", tjtype); + } else { + tjtype = "涓汉"; + data.put("tjtype", tjtype); + } + data.put("dstype", "缁熶竴"); + data.put("sex", sex); + data.put("age", DateUtil.ageOfNow(tjCustomer.getCusBrithday())); + data.put("tjnumber", tjNumber); + data.put("tjdate", DateUtils.parseDateToStr("yyyy/MM/dd", tjOrder.getCreateTime())); + data.put("phone", tjCustomer.getCusPhone()); + data.put("idcard", MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard())); + data.put("num2", 0); + data.put("num3", 4); + } + + 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.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); // 閿佸畾琛ㄦ牸瀹藉害 + for (String title : titles) { + PdfPCell cell = new PdfPCell(new Paragraph(title, headFont)); + cell.setBorder(Rectangle.NO_BORDER); // 绉婚櫎鍗曞厓鏍艰竟妗� + table.addCell(cell); + } + for (TjPdfVO item : list) { + PdfPCell nameCell = new PdfPCell(new Paragraph(StrUtil.isNotBlank(item.getProName()) && !item.getProName().equals("null")?item.getProName():"", textFont)); + nameCell.setBorder(Rectangle.NO_BORDER); // 绉婚櫎鍗曞厓鏍艰竟妗� + table.addCell(nameCell); + + PdfPCell resultCell = new PdfPCell(new Paragraph(StrUtil.isNotBlank(item.getProResult()) && !item.getProResult().equals("null") ?item.getProResult():"", textFont)); + resultCell.setBorder(Rectangle.NO_BORDER); // 绉婚櫎鍗曞厓鏍艰竟妗� + table.addCell(resultCell); + + PdfPCell companyCell = new PdfPCell(new Paragraph(StrUtil.isNotBlank(item.getCompany()) && !item.getCompany().equals("null") ?item.getCompany():"", textFont)); + companyCell.setBorder(Rectangle.NO_BORDER); // 绉婚櫎鍗曞厓鏍艰竟妗� + table.addCell(companyCell); + + PdfPCell standardValueCell = new PdfPCell(new Paragraph(StrUtil.isNotBlank(item.getStandardValue()) && !item.getStandardValue().equals("null") ?item.getStandardValue():"", textFont)); + standardValueCell.setBorder(Rectangle.NO_BORDER); // 绉婚櫎鍗曞厓鏍艰竟妗� + table.addCell(standardValueCell); + } + // 灏嗚〃鏍兼坊鍔犲埌鏂囨。 + document.add(table); + } + } -- Gitblit v1.8.0