|
@@ -2,13 +2,24 @@ package org.springblade.business.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.lowagie.text.Document;
|
|
|
|
+import com.lowagie.text.DocumentException;
|
|
|
|
+import com.lowagie.text.Font;
|
|
|
|
+import com.lowagie.text.Paragraph;
|
|
|
|
+import com.lowagie.text.pdf.BaseFont;
|
|
|
|
+import com.lowagie.text.pdf.PdfPTable;
|
|
|
|
+import com.lowagie.text.pdf.PdfWriter;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
|
|
+import org.springblade.business.entity.TrialMaterialMobilization;
|
|
import org.springblade.business.entity.TrialSampleInfo;
|
|
import org.springblade.business.entity.TrialSampleInfo;
|
|
|
|
+import org.springblade.business.excel.TrialMaterialMobilizationExcel;
|
|
import org.springblade.business.excel.TrialSampleInfoExcel;
|
|
import org.springblade.business.excel.TrialSampleInfoExcel;
|
|
import org.springblade.business.mapper.TrialSampleInfoMapper;
|
|
import org.springblade.business.mapper.TrialSampleInfoMapper;
|
|
import org.springblade.business.service.ITrialSampleInfoService;
|
|
import org.springblade.business.service.ITrialSampleInfoService;
|
|
|
|
+import org.springblade.business.utils.PDFUtil;
|
|
|
|
+import org.springblade.business.utils.SystemUtils;
|
|
import org.springblade.business.vo.TrialSampleInfoVO;
|
|
import org.springblade.business.vo.TrialSampleInfoVO;
|
|
import org.springblade.business.wrapper.TrialSampleInfoWarpper;
|
|
import org.springblade.business.wrapper.TrialSampleInfoWarpper;
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
@@ -16,12 +27,19 @@ import org.springblade.core.log.exception.ServiceException;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
import org.springblade.core.mp.support.Condition;
|
|
import org.springblade.core.mp.support.Condition;
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
|
+import org.springblade.core.tool.api.R;
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -29,6 +47,8 @@ import java.util.List;
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
public class TrialSampleInfoServiceImpl extends BaseServiceImpl<TrialSampleInfoMapper, TrialSampleInfo> implements ITrialSampleInfoService {
|
|
public class TrialSampleInfoServiceImpl extends BaseServiceImpl<TrialSampleInfoMapper, TrialSampleInfo> implements ITrialSampleInfoService {
|
|
|
|
|
|
|
|
+ private final IUserClient iUserClient;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public TrialSampleInfo sampleDetail(Long id) {
|
|
public TrialSampleInfo sampleDetail(Long id) {
|
|
return baseMapper.selectById(id);
|
|
return baseMapper.selectById(id);
|
|
@@ -90,5 +110,113 @@ public class TrialSampleInfoServiceImpl extends BaseServiceImpl<TrialSampleInfoM
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void sampleExportPdf(String ids, HttpServletResponse response) {
|
|
|
|
+ try {
|
|
|
|
+ String fileName = java.net.URLEncoder.encode(DateUtil.time() + ".pdf", "UTF-8");
|
|
|
|
+ response.reset();
|
|
|
|
+ response.setContentType("application/pdf; name=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
|
|
|
|
+ response.setHeader("Content-Disposition", "inline; filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
|
|
|
|
+ //构建字节输出流
|
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
+
|
|
|
|
+ //构造数据
|
|
|
|
+ List<TrialSampleInfo> list = baseMapper.selectBatchIds(Func.toLongList(ids));
|
|
|
|
+ List<TrialSampleInfoExcel> pdfData = new ArrayList<>();
|
|
|
|
+ for (TrialSampleInfo trialSampleInfo : list) {
|
|
|
|
+ R<User> userR = iUserClient.userInfoById(trialSampleInfo.getUserId());
|
|
|
|
+ TrialSampleInfoExcel trialSampleInfoExcel = BeanUtil.copyProperties(trialSampleInfo, TrialSampleInfoExcel.class);
|
|
|
|
+ assert trialSampleInfoExcel != null;
|
|
|
|
+ trialSampleInfoExcel.setUserName(userR.getData().getName());
|
|
|
|
+ pdfData.add(trialSampleInfoExcel);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //创建文档,设置页面大小、左右上下边距
|
|
|
|
+ Document document = new Document();
|
|
|
|
+
|
|
|
|
+ BaseFont bfChinese = null;
|
|
|
|
+ //处理中文显示问题,使用资源字体
|
|
|
|
+ if (SystemUtils.isWindows()) {
|
|
|
|
+ //windows
|
|
|
|
+ bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMYOU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
|
|
|
+ }
|
|
|
|
+ if (SystemUtils.isLinux()) {
|
|
|
|
+ //linux
|
|
|
|
+ bfChinese = BaseFont.createFont("/usr/share/fonts/my-fonts/SIMYOU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //Font dateTitle = new Font(bfChinese, 7, Font.NORMAL);
|
|
|
|
+ //Font title = new Font(bfChinese, 12, Font.BOLD);//文字加粗
|
|
|
|
+ Font textFont = new Font(bfChinese, 7, Font.NORMAL);//文字正常
|
|
|
|
+
|
|
|
|
+ //设置分页
|
|
|
|
+ PdfWriter.getInstance(document, byteArrayOutputStream);
|
|
|
|
+
|
|
|
|
+ //打开文档
|
|
|
|
+ document.open();
|
|
|
|
+
|
|
|
|
+ //标题
|
|
|
|
+ PdfPTable tableTitle = new PdfPTable(3);
|
|
|
|
+ //生成一个9列的表格
|
|
|
|
+ PdfPTable table = new PdfPTable(9);
|
|
|
|
+
|
|
|
|
+ //定义每个单元格的宽度
|
|
|
|
+ float[] widthsHeaderTitle = {1f, 1f, 1f};
|
|
|
|
+ float[] widthsHeader = {1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f};
|
|
|
|
+
|
|
|
|
+ float lineHeight = (float) 20.0;
|
|
|
|
+
|
|
|
|
+ //设置表格每一格的宽度
|
|
|
|
+ tableTitle.setWidths(widthsHeaderTitle);
|
|
|
|
+ table.setWidths(widthsHeader);
|
|
|
|
+
|
|
|
|
+ //设置表格总体宽度
|
|
|
|
+ tableTitle.setWidthPercentage(100);
|
|
|
|
+ table.setWidthPercentage(100);
|
|
|
|
+
|
|
|
|
+ int colSpan = 1;
|
|
|
|
+
|
|
|
|
+ /*SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ Date date = new Date(System.currentTimeMillis());
|
|
|
|
+ //添加标题
|
|
|
|
+ PDFUtil.createTableCellLeft("导出人:XXX", textFont, tableTitle, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCellCenter("XXX表", title, tableTitle, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCellRight(formatter.format(date), dateTitle, tableTitle, lineHeight, colSpan);*/
|
|
|
|
+
|
|
|
|
+ document.add(tableTitle);
|
|
|
|
+ document.add(new Paragraph("\n"));
|
|
|
|
+
|
|
|
|
+ String[] array = {"取样名称", "取样日期", "取样编号", "规格型号", "试样数量", "计算单位", "拟用部位", "代表数量","取样人"};
|
|
|
|
+ for (String s : array) {
|
|
|
|
+ PDFUtil.createTableCell(s, textFont, table, lineHeight, colSpan);
|
|
|
|
+ }
|
|
|
|
+ for (TrialSampleInfoExcel pdfDatum : pdfData) {
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getMaterialName(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(DateUtil.formatDate(pdfDatum.getSamplingDate()), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(String.valueOf(pdfDatum.getId()), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getSpecificationModel(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(String.valueOf(pdfDatum.getMaterialCount()), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getCalculationUnit(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getProposedPosition(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(String.valueOf(pdfDatum.getRepresentativeCount()), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getUserName(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ }
|
|
|
|
+ document.add(table);
|
|
|
|
+ document.close();
|
|
|
|
+ try {
|
|
|
|
+ byteArrayOutputStream.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //输出
|
|
|
|
+ ServletOutputStream os = response.getOutputStream();
|
|
|
|
+ os.write(byteArrayOutputStream.toByteArray());
|
|
|
|
+
|
|
|
|
+ } catch (DocumentException | IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|