|
|
|
@ -0,0 +1,170 @@ |
|
|
|
package com.hxhq.business.utils.pdf.resource; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.hxhq.business.domain.Mjy; |
|
|
|
import com.hxhq.business.domain.MjyJcgj; |
|
|
|
import com.hxhq.business.domain.MjyTz; |
|
|
|
import com.hxhq.business.dto.mjy.DetailDto; |
|
|
|
import com.hxhq.business.utils.pdf.PdfBaseUtil; |
|
|
|
import com.hxhq.common.core.utils.StringUtils; |
|
|
|
import com.hxhq.common.security.utils.SecurityUtils; |
|
|
|
import com.hxhq.system.api.model.LoginUser; |
|
|
|
import com.itextpdf.text.*; |
|
|
|
import com.itextpdf.text.pdf.BaseFont; |
|
|
|
import com.itextpdf.text.pdf.PdfPCell; |
|
|
|
import com.itextpdf.text.pdf.PdfPTable; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* 麻精药详情 |
|
|
|
* |
|
|
|
* @author tanfei |
|
|
|
*/ |
|
|
|
public class Drug { |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(Drug.class.getName()); |
|
|
|
|
|
|
|
/** |
|
|
|
* 导出 |
|
|
|
* |
|
|
|
* @param mjy |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public String exportDetail(DetailDto mjy, List<MjyTz> mjyTzList, List<MjyJcgj> mjyJcgjList, String localFilePath) { |
|
|
|
Document document = null; |
|
|
|
FileOutputStream fos = null; |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
String filePath = PdfBaseUtil.getFilePath(localFilePath); |
|
|
|
try { |
|
|
|
String sign="华西海圻"; |
|
|
|
LoginUser loginUser=SecurityUtils.getLoginUser(); |
|
|
|
if(loginUser!=null){ |
|
|
|
sign=loginUser.getSysUser().getNickName(); |
|
|
|
} |
|
|
|
document = PdfBaseUtil.init(document, fos, filePath, sign+sdf.format(new Date()), mjy.getMc()); |
|
|
|
// 基本信息 |
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "基本信息", 10,true); |
|
|
|
Map<String, String> formData1 = new LinkedHashMap<>(); |
|
|
|
formData1.put("名称", mjy.getMc()); |
|
|
|
formData1.put("编号", mjy.getBh()); |
|
|
|
formData1.put("浓度", mjy.getNd() + mjy.getNddw()); |
|
|
|
formData1.put("库存量", mjy.getKc() + mjy.getKcdw()); |
|
|
|
formData1.put("失效日期", sdf.format(mjy.getSxrq())); |
|
|
|
formData1.put("存储条件", mjy.getCctj()); |
|
|
|
formData1.put("存储位置", mjy.getCcwz()); |
|
|
|
PdfBaseUtil.addFormTableColumns(document, formData1, 2); |
|
|
|
// 表单信息 |
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "表单信息", 10,true); |
|
|
|
Map<String, String> formData3 = new LinkedHashMap<>(); |
|
|
|
formData3.put("所属表单", mjy.getBdMc()); |
|
|
|
formData3.put("所属试验信息", mjy.getStudyMc()); |
|
|
|
formData3.put("表单所属人", mjy.getBdgsrMc()); |
|
|
|
PdfBaseUtil.addFormTableColumns(document, formData3, 2); |
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "麻精药台账", 10,true); |
|
|
|
// 台账 |
|
|
|
addTz(document,mjyTzList); |
|
|
|
//稽查轨迹 |
|
|
|
addJcgj(document,mjyJcgjList); |
|
|
|
logger.info("生成成功:{}", filePath); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("生成失败", e); |
|
|
|
throw new RuntimeException("生成失败: " + e.getMessage()); |
|
|
|
} finally { |
|
|
|
if (document != null) { |
|
|
|
document.close(); |
|
|
|
} |
|
|
|
if (fos != null) { |
|
|
|
try { |
|
|
|
fos.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
logger.error("关闭文件流失败", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return filePath; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 台账 |
|
|
|
* @param document |
|
|
|
* @param mjyTzList |
|
|
|
* @throws IOException |
|
|
|
* @throws DocumentException |
|
|
|
*/ |
|
|
|
public void addTz(Document document,List<MjyTz> mjyTzList) throws IOException, DocumentException { |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
// 9. 表头 |
|
|
|
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); |
|
|
|
Font headerFont = new Font(bfChinese, 10, Font.NORMAL); |
|
|
|
Font contentFont = new Font(bfChinese, 10, Font.NORMAL); |
|
|
|
// 8. 创建表格 |
|
|
|
PdfPTable table = new PdfPTable(7); |
|
|
|
table.setWidthPercentage(100); |
|
|
|
String[] headers = {"使用人", "领取/归还人", "发放/接收人", "操作类型", "操作量", "备注/原因", "操作时间"}; |
|
|
|
for (String header : headers) { |
|
|
|
PdfPCell cell = new PdfPCell(new Phrase(header, headerFont)); |
|
|
|
cell.setHorizontalAlignment(Element.ALIGN_CENTER); |
|
|
|
cell.setPadding(8); |
|
|
|
cell.setBorderWidth(1); |
|
|
|
table.addCell(cell); |
|
|
|
} |
|
|
|
int rowNum = 0; |
|
|
|
for (MjyTz mjyTz : mjyTzList) { |
|
|
|
// 交替行颜色 |
|
|
|
if (rowNum % 2 == 0) { |
|
|
|
table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); |
|
|
|
} else { |
|
|
|
table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); |
|
|
|
} |
|
|
|
table.addCell(PdfBaseUtil.createCell(mjyTz.getQmrMc(), contentFont)); |
|
|
|
table.addCell(PdfBaseUtil.createCell(StringUtils.isNoneBlank(mjyTz.getLqrMc())?mjyTz.getLqrMc():""+(StringUtils.isNoneBlank(mjyTz.getGhrMc())?mjyTz.getGhrMc():""), contentFont)); |
|
|
|
table.addCell(PdfBaseUtil.createCell(StringUtils.isNoneBlank(mjyTz.getFfrMc())?mjyTz.getFfrMc():""+(StringUtils.isNoneBlank(mjyTz.getJsrMc())?mjyTz.getJsrMc():""), contentFont)); |
|
|
|
table.addCell(PdfBaseUtil.createCell(mjyTz.getQmyy(), contentFont)); |
|
|
|
table.addCell(PdfBaseUtil.createCell(mjyTz.getCzl()+mjyTz.getCzldw(), contentFont)); |
|
|
|
table.addCell(PdfBaseUtil.createCell(mjyTz.getRemark(), contentFont)); |
|
|
|
table.addCell(PdfBaseUtil.createCell(sdf.format(mjyTz.getCreateTime()), contentFont)); |
|
|
|
rowNum++; |
|
|
|
} |
|
|
|
document.add(table); |
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, "稽查轨迹", 10,true); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 稽查轨迹 |
|
|
|
* @param document |
|
|
|
* @param mjyJcgjList |
|
|
|
* @throws IOException |
|
|
|
* @throws DocumentException |
|
|
|
*/ |
|
|
|
public void addJcgj(Document document,List<MjyJcgj> mjyJcgjList) throws IOException, DocumentException { |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
for (MjyJcgj mjyJcgj : mjyJcgjList) { |
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, sdf.format(mjyJcgj.getCreateTime())+" "+mjyJcgj.getJcmc() , 10,false); |
|
|
|
StringJoiner result = new StringJoiner(", "); |
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
JsonNode jsonArray = mapper.readTree(mjyJcgj.getJcnr()); |
|
|
|
for (JsonNode node : jsonArray) { |
|
|
|
String name = node.get("name").asText(); |
|
|
|
String value = node.get("value").asText(); |
|
|
|
result.add(name + ":" + value); |
|
|
|
} |
|
|
|
if(StringUtils.isNoneBlank(mjyJcgj.getRemark())){ |
|
|
|
result.add("备注:"+mjyJcgj.getRemark()); |
|
|
|
} |
|
|
|
if(StringUtils.isNoneBlank(mjyJcgj.getRemark())){ |
|
|
|
result.add("签名人:"+mjyJcgj.getQmrMc()); |
|
|
|
} |
|
|
|
PdfBaseUtil.addUnderlinedTitle(document, result.toString(), 10,false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |