|
@@ -0,0 +1,163 @@
|
|
|
+package org.springblade.manager.service.impl;
|
|
|
+
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.jsoup.Jsoup;
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
+import org.jsoup.nodes.Element;
|
|
|
+import org.jsoup.select.Elements;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
+import org.springblade.core.ribbon.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.core.tool.utils.IoUtil;
|
|
|
+import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
+import org.springblade.manager.entity.SignPfxFilePre;
|
|
|
+import org.springblade.manager.entity.TextdictInfo;
|
|
|
+import org.springblade.manager.mapper.SignPfxFilePreMapper;
|
|
|
+import org.springblade.manager.service.ISignPfxFilePreService;
|
|
|
+import org.springblade.manager.utils.FileUtils;
|
|
|
+import org.springblade.manager.utils.PdfAddimgUtil;
|
|
|
+import org.springblade.manager.vo.SignPfxFilePreVo;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class SignPfxFilePreServiceImpl implements ISignPfxFilePreService {
|
|
|
+ @Autowired
|
|
|
+ private SignPfxFilePreMapper signPfxFilePreMapper;
|
|
|
+
|
|
|
+ private final String excelTabFileUrl = "https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240731/cf9534fd3ac688df5f9d7a802ba754c0.xlsx";
|
|
|
+ private final String wbsHtmlUrl = "/www/wwwroot/Users/hongchuangyanfa/Desktop/privateUrl/1771066158930198528.html";
|
|
|
+ @Autowired
|
|
|
+ private BeanUtil beanUtil;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R picPresave(SignPfxFilePreVo vo) throws IOException {
|
|
|
+ MultipartFile file1 = vo.getFile();
|
|
|
+ //图片保存到本地
|
|
|
+ String file_path = FileUtils.getSysLocalFileUrl();
|
|
|
+ String localImgPath = file_path + "print//" + UUID.randomUUID() + ".png";
|
|
|
+ // 检查文件是否存在
|
|
|
+ File file = new File(localImgPath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ // 如果文件不存在,则创建目录
|
|
|
+ File parentDir = file.getParentFile();
|
|
|
+ if (parentDir != null && !parentDir.exists()) {
|
|
|
+ parentDir.mkdirs();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 保存文件
|
|
|
+ file1.transferTo(file);
|
|
|
+ SignPfxFilePre signPfxFilePre = new SignPfxFilePre();
|
|
|
+ org.springblade.core.tool.utils.BeanUtil.copyProperties(vo, signPfxFilePre);
|
|
|
+ signPfxFilePre.setSignaturePngUrl(localImgPath);
|
|
|
+ signPfxFilePreMapper.insert(signPfxFilePre);
|
|
|
+ SignPfxFilePre signPfxFilePre1 = signPfxFilePreMapper.selectByPrimaryKey(signPfxFilePre.getId());
|
|
|
+ return R.data(signPfxFilePre1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R prePicture(SignPfxFilePre signPfxFilePre) throws Exception {
|
|
|
+ SignPfxFilePre spr = signPfxFilePreMapper.selectByPrimaryKey(signPfxFilePre.getId());
|
|
|
+ //宽度
|
|
|
+ Double wide = spr.getWide();
|
|
|
+ //高度
|
|
|
+ Double hight = spr.getHigh();
|
|
|
+ //图片地址
|
|
|
+ String localImgPath = spr.getSignaturePngUrl();
|
|
|
+ String file_path = FileUtils.getSysLocalFileUrl();
|
|
|
+
|
|
|
+ //图片压缩后的地址
|
|
|
+ UUID uuid = UUID.randomUUID();
|
|
|
+ String compressImgPath = file_path + "/print//" + uuid + ".png";
|
|
|
+
|
|
|
+ String pdfPath = file_path + "/pdf//" + "1751795857679712265" + ".pdf";
|
|
|
+ String excelPath = file_path + "/pdf//" + uuid + ".xlsx";
|
|
|
+
|
|
|
+ File tabPdf = ResourceUtil.getFile(pdfPath);
|
|
|
+ if (tabPdf.exists()) {
|
|
|
+ tabPdf.delete();
|
|
|
+ }
|
|
|
+ //获取excel流 和 html流
|
|
|
+ InputStream exceInp = CommonUtil.getOSSInputStream(excelTabFileUrl);
|
|
|
+
|
|
|
+ Workbook workbook = null;
|
|
|
+ int index = excelTabFileUrl.lastIndexOf(".");
|
|
|
+ String suffix = excelTabFileUrl.substring(index);
|
|
|
+
|
|
|
+ if (".xls".equals(suffix)) {
|
|
|
+ workbook = new XSSFWorkbook(exceInp);
|
|
|
+ } else if (".xlsx".equals(suffix)) {
|
|
|
+ workbook = new XSSFWorkbook(exceInp);
|
|
|
+ }
|
|
|
+ //获取工作表
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ sheet.setForceFormulaRecalculation(true);
|
|
|
+ List<String> sign = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotEmpty(wbsHtmlUrl)) {
|
|
|
+ InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(wbsHtmlUrl);
|
|
|
+ String htmlString = IoUtil.readToString(inputStreamByUrl);
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ Element table = doc.select("table").first();
|
|
|
+ Elements dqids = table.getElementsByAttribute("dqid");
|
|
|
+ for (Element element : dqids) {
|
|
|
+ String dqid = element.attr("dqid");
|
|
|
+ Elements x11 = element.getElementsByAttribute("x1");
|
|
|
+ if (x11 != null && x11.size() >= 1) {
|
|
|
+ Element element1 = x11.get(x11.size() - 1);
|
|
|
+ int x1 = Func.toInt(element1.attr("x1"));
|
|
|
+ int y1 = Func.toInt(element1.attr("y1"));
|
|
|
+ Row row = sheet.getRow(y1 - 1);
|
|
|
+ if (row != null) {
|
|
|
+ Cell cell = row.getCell(x1 - 1);
|
|
|
+ if (cell != null || ObjectUtils.isNotEmpty(cell)) {
|
|
|
+ short fontIndex = cell.getCellStyle().getFontIndex();
|
|
|
+ Font oldfontAt = workbook.getFontAt(fontIndex);
|
|
|
+ Font redFont = workbook.createFont();
|
|
|
+ redFont.setColor(IndexedColors.WHITE.getIndex()); //设置字体颜色
|
|
|
+ redFont.setFontHeightInPoints(Short.valueOf("1"));//设置字体大小
|
|
|
+ redFont.setFontName(oldfontAt.getFontName());//设置字体
|
|
|
+ String CellValue = cell.getStringCellValue().trim();
|
|
|
+
|
|
|
+ CellStyle newStyle = workbook.createCellStyle(); //创建单元格样式
|
|
|
+ newStyle.cloneStyleFrom(cell.getCellStyle());
|
|
|
+ newStyle.setFont(redFont);
|
|
|
+ newStyle.setShrinkToFit(true);
|
|
|
+ cell.setCellStyle(newStyle);
|
|
|
+ if(dqid.contains("||")){
|
|
|
+ String[] split = dqid.split("\\|\\|");
|
|
|
+ for (String singleDqid : split) {
|
|
|
+ cell.setCellValue(singleDqid);
|
|
|
+ sign.add(singleDqid);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ cell.setCellValue(dqid);
|
|
|
+ sign.add(dqid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<Long, TextdictInfo> textMap = new HashMap<>();
|
|
|
+ //输出流
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(excelPath);
|
|
|
+ workbook.write(outputStream);
|
|
|
+ FileUtils.excelToPdf(excelPath, pdfPath);
|
|
|
+ FileUtils.compressImage(localImgPath,compressImgPath, spr.getWide(),spr.getHigh());
|
|
|
+ PdfAddimgUtil.pdfAddImgInfoNew(pdfPath, String.join(",", sign),textMap,compressImgPath);
|
|
|
+ //压缩后的图片上传oss
|
|
|
+ return R.data(FileUtils.getNetUrl(pdfPath));
|
|
|
+ }
|
|
|
+}
|