|
@@ -2,12 +2,23 @@ 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.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+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 com.sun.org.apache.regexp.internal.RE;
|
|
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.TrialMaterialMobilization;
|
|
|
|
+import org.springblade.business.excel.TrialMaterialMobilizationExcel;
|
|
import org.springblade.business.mapper.TrialMaterialMobilizationMapper;
|
|
import org.springblade.business.mapper.TrialMaterialMobilizationMapper;
|
|
import org.springblade.business.service.ITrialMaterialMobilizationService;
|
|
import org.springblade.business.service.ITrialMaterialMobilizationService;
|
|
|
|
+import org.springblade.business.utils.PDFUtil;
|
|
import org.springblade.business.vo.TrialMaterialMobilizationVO;
|
|
import org.springblade.business.vo.TrialMaterialMobilizationVO;
|
|
import org.springblade.business.wrapper.TrialMaterialMobilizationWarpper;
|
|
import org.springblade.business.wrapper.TrialMaterialMobilizationWarpper;
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
@@ -15,17 +26,30 @@ 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.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.*;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
public class TrialMaterialMobilizationServiceImpl extends BaseServiceImpl<TrialMaterialMobilizationMapper, TrialMaterialMobilization> implements ITrialMaterialMobilizationService {
|
|
public class TrialMaterialMobilizationServiceImpl extends BaseServiceImpl<TrialMaterialMobilizationMapper, TrialMaterialMobilization> implements ITrialMaterialMobilizationService {
|
|
|
|
|
|
|
|
+ private final static String SIMYOU_TTF = "classpath:templates/SIMYOU.TTF";
|
|
|
|
+ private final IUserClient iUserClient;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean mobilizationSubmit(TrialMaterialMobilization obj) {
|
|
public boolean mobilizationSubmit(TrialMaterialMobilization obj) {
|
|
if (ObjectUtil.isEmpty(SecureUtil.getUserId())) {
|
|
if (ObjectUtil.isEmpty(SecureUtil.getUserId())) {
|
|
@@ -70,4 +94,134 @@ public class TrialMaterialMobilizationServiceImpl extends BaseServiceImpl<TrialM
|
|
List<TrialMaterialMobilizationVO> records = trialMaterialMobilizationVOIPage.getRecords();
|
|
List<TrialMaterialMobilizationVO> records = trialMaterialMobilizationVOIPage.getRecords();
|
|
return trialMaterialMobilizationVOIPage.setRecords(records);
|
|
return trialMaterialMobilizationVOIPage.setRecords(records);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<TrialMaterialMobilization> selectList() {
|
|
|
|
+ return baseMapper.selectList(Wrappers.<TrialMaterialMobilization>query().lambda().eq(TrialMaterialMobilization::getStatus, 1));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void importMobilization(List<TrialMaterialMobilizationExcel> data, Boolean isCovered) {
|
|
|
|
+ List<TrialMaterialMobilization> list = new ArrayList<>();
|
|
|
|
+ if (ObjectUtil.isEmpty(SecureUtil.getUserId())) {
|
|
|
|
+ throw new ServiceException("获取用户信息失败");
|
|
|
|
+ }
|
|
|
|
+ data.forEach(excel -> {
|
|
|
|
+ TrialMaterialMobilization trialMaterialMobilization = BeanUtil.copyProperties(excel, TrialMaterialMobilization.class);
|
|
|
|
+ assert trialMaterialMobilization != null;
|
|
|
|
+ trialMaterialMobilization.setUserId(SecureUtil.getUserId());
|
|
|
|
+ list.add(trialMaterialMobilization);
|
|
|
|
+ });
|
|
|
|
+ if (isCovered) {
|
|
|
|
+ this.saveOrUpdateBatch(list);
|
|
|
|
+ } else {
|
|
|
|
+ this.saveBatch(list);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void mobilizationExportPdf(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<TrialMaterialMobilization> list = baseMapper.selectBatchIds(Func.toLongList(ids));
|
|
|
|
+ List<TrialMaterialMobilizationExcel> pdfData = new ArrayList<>();
|
|
|
|
+ for (TrialMaterialMobilization trialMaterialMobilization : list) {
|
|
|
|
+ R<User> userR = iUserClient.userInfoById(trialMaterialMobilization.getUserId());
|
|
|
|
+ TrialMaterialMobilizationExcel trialMaterialMobilizationExcel = BeanUtil.copyProperties(trialMaterialMobilization, TrialMaterialMobilizationExcel.class);
|
|
|
|
+ assert trialMaterialMobilizationExcel != null;
|
|
|
|
+ trialMaterialMobilizationExcel.setUserName(userR.getData().getName());
|
|
|
|
+ pdfData.add(trialMaterialMobilizationExcel);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //创建文档,设置页面大小、左右上下边距
|
|
|
|
+ Document document = new Document();
|
|
|
|
+
|
|
|
|
+ //处理中文显示问题,使用资源字体
|
|
|
|
+ BaseFont bfChinese = BaseFont.createFont(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);
|
|
|
|
+ //生成一个13列的表格
|
|
|
|
+ PdfPTable table = new PdfPTable(13);
|
|
|
|
+
|
|
|
|
+ //定义每个单元格的宽度
|
|
|
|
+ float[] widthsHeaderTitle = {1f, 1f, 1f};
|
|
|
|
+ float[] widthsHeader = {1f, 1f, 1f, 1f, 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 (TrialMaterialMobilizationExcel pdfDatum : pdfData) {
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getId().toString(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(DateUtil.formatDate(pdfDatum.getMobilizationDate()), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getMaterialName(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getMaterialType().toString(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getSpecificationModel(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getSupplierUnit(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getMaterialPrice().toString(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getMaterialCount().toString(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getCalculationUnit(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getBatchNumber().toString(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getPlaceOfProduction(), textFont, table, lineHeight, colSpan);
|
|
|
|
+ PDFUtil.createTableCell(pdfDatum.getProposedPosition(), 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();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|