From 6f0797731657022e9812b92fb4d78bcf56a65c1d Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期一, 05 一月 2026 00:00:16 +0800
Subject: [PATCH] 修改了对应代码
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java | 184 +++++++++++++++++-----
ruoyi-admin/src/main/resources/application-druid.yml | 2
archiveManager/src/main/java/com/ruoyi/domain/dto/searSigAnn.java | 12 +
ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/ArchiveRecordsController.java | 36 ++-
ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java | 199 +++++++++++++++++++++---
ruoyi-admin/src/main/resources/application.yml | 5
archiveManager/src/main/java/com/ruoyi/service/impl/DocumentMaterialsServiceImpl.java | 2
7 files changed, 351 insertions(+), 89 deletions(-)
diff --git a/archiveManager/src/main/java/com/ruoyi/domain/dto/searSigAnn.java b/archiveManager/src/main/java/com/ruoyi/domain/dto/searSigAnn.java
new file mode 100644
index 0000000..ebaa946
--- /dev/null
+++ b/archiveManager/src/main/java/com/ruoyi/domain/dto/searSigAnn.java
@@ -0,0 +1,12 @@
+package com.ruoyi.domain.dto;
+
+import lombok.Data;
+
+@Data
+public class searSigAnn {
+ private String[] selectedAnnotations;
+ private String[] selectedSignatures;
+ private Long recordId;
+
+ private Boolean includeQrCode;
+}
diff --git a/archiveManager/src/main/java/com/ruoyi/service/impl/DocumentMaterialsServiceImpl.java b/archiveManager/src/main/java/com/ruoyi/service/impl/DocumentMaterialsServiceImpl.java
index 4a1b581..089753a 100644
--- a/archiveManager/src/main/java/com/ruoyi/service/impl/DocumentMaterialsServiceImpl.java
+++ b/archiveManager/src/main/java/com/ruoyi/service/impl/DocumentMaterialsServiceImpl.java
@@ -473,6 +473,8 @@
newRecord.setFileSize(null);
newRecord.setFormat(null);
newRecord.setUrl(null);
+ newRecord.setVisible(0);
+
// 娣诲姞鍒颁腑闂磋褰曞垪琛�
middleRecords.add(newRecord);
}
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/ArchiveRecordsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/ArchiveRecordsController.java
index 5c4332c..ead5dca 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/ArchiveRecordsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/ArchiveRecordsController.java
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
@@ -16,11 +17,13 @@
import com.ruoyi.common.utils.poi.ExcelUtilManySheetFour;
import com.ruoyi.domain.ArchiveRecords;
import com.ruoyi.domain.DocumentMaterials;
+import com.ruoyi.domain.dto.searSigAnn;
import com.ruoyi.domain.vo.*;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.service.IArchiveRecordsService;
import com.ruoyi.service.IDocumentMaterialsService;
import com.ruoyi.service.impl.BarcodeService;
+import com.ruoyi.service.impl.pdfGenerateService;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
@@ -51,6 +54,9 @@
private IArchiveRecordsService archiveRecordsService;
@Autowired
private BarcodeService barcodeService;
+
+ @Autowired
+ private pdfGenerateService pdfGenerateService;
@Autowired
private IDocumentMaterialsService iDocumentMaterialsService;
@@ -225,23 +231,22 @@
return AjaxResult.success( archiveRecordsService.whether(recordId));
}
- @PostMapping(value={"/recordFileList/{includeQrCode}/{selectedSignatures}/{selectedAnnotations}", "/recordFileList/{includeQrCode}", "/recordFileList/{includeQrCode}/{selectedSignatures}","/recordFileList/{includeQrCode}/{selectedAnnotations}"})
+ @PostMapping("/recordFileList")
//瀵煎嚭excle
- public void getSpecialArchiveInfo(HttpServletResponse response, @RequestParam("recordId")Long recordId, @PathVariable(name = "includeQrCode",required = false) boolean includeQrCode, @PathVariable(name = "selectedSignatures",required = false) int[] selectedSignatures, @PathVariable(name = "selectedAnnotations",required = false) int[] selectedAnnotations) throws IOException {
+ public void getSpecialArchiveInfo(HttpServletResponse response, @RequestBody searSigAnn searSigAnn) throws IOException {
System.out.println("uuuuuuuuuuuuuuuuuuusssss88888888888888");
-// System.out.println(selectedSignatures[0]);
-// System.out.println(selectedAnnotations[0]);
- System.out.println(includeQrCode);
- //浜岀淮鐮佹槸鍚︾敓鎴�
+ //System.out.println(includeQrCode);
+ //鐢熸垚浜岀淮鐮�
String code = "2024050000029250";
byte [] bt = barcodeService.generateBarcodeImage(code);
+ // System.out.println(Arrays.toString(selectedSignatures));
//绛惧悕閫夋嫨
String [] sig = {"涓氬姟绉戝绉讳氦浜�:","瀹℃壒绉戠Щ浜や汉:","妗f鏁寸悊鍏徃:"};
List<String> arrLis = new ArrayList<>();
- if(selectedSignatures!=null){
- for(int si: selectedSignatures)
+ if(searSigAnn.getSelectedSignatures()!=null){
+ for(String si: searSigAnn.getSelectedSignatures())
{
- arrLis.add(sig[si]);
+ arrLis.add(sig[Integer.parseInt(si)]);
}
}
//娉ㄩ�夋嫨
@@ -251,15 +256,15 @@
"淇濈鏈熼檺:30骞存垨姘镐箙",
"椤靛彿鎸夌収姝e紡褰曞叆椤电爜涓哄噯"};
List<String> arrAn = new ArrayList<>();
- if(selectedAnnotations!=null) {
- for (int ar : selectedAnnotations) {
- arrAn.add(ann[ar]);
+ if(searSigAnn.getSelectedAnnotations()!=null) {
+ for (String ar : searSigAnn.getSelectedAnnotations()) {
+ arrAn.add(ann[Integer.parseInt(ar)]);
}
}
List<DocumentMaterialsFileList> arsi = new ArrayList<>();
// DocumentMaterials documentMaterials = new DocumentMaterials();
// documentMaterials.setRecordId(recordId);
- List<DocumentMaterialsFileList> lst = iDocumentMaterialsService.selectDocumentMaterialsFileList(recordId);
+ List<DocumentMaterialsFileList> lst = iDocumentMaterialsService.selectDocumentMaterialsFileList(searSigAnn.getRecordId());
@@ -288,6 +293,9 @@
inquiryNumber = arsi.get(0).getInquiryNumber();
caseTitle = arsi.get(0).getCaseTitle();
}
- util3.exportExcelManySheet(response, mysheet1, includeQrCode,bt, arrLis, arrAn, inquiryNumber, caseTitle);
+ util3.exportExcelManySheet(response, mysheet1, searSigAnn.getIncludeQrCode(), bt, arrLis, arrAn, inquiryNumber, caseTitle);
}
}
+
+
+
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java
index 6adca94..710af70 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/DocumentMaterialsController.java
@@ -68,6 +68,7 @@
import static com.ruoyi.common.core.page.TableSupport.PAGE_NUM;
import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE;
+import static com.ruoyi.framework.datasource.DynamicDataSourceContextHolder.log;
/**
* 銆愭枃浠舵潗鏂欑患鍚堜俊鎭�慍ontroller
@@ -92,6 +93,11 @@
@Autowired
private IArchiveRecordsService iArchiveRecordsService;
+
+ /**
+ * 鏂囦欢鍒嗛殧绗�
+ */
+ private static final String FILE_DELIMETER = ",";
/**
* 鍒ゆ柇PageNumber鏄惁杩炵画
*/
@@ -179,41 +185,47 @@
@PostMapping("/exportDir")
public void exportDir(HttpServletResponse response, DocumentMaterials documentMaterials, @RequestParam(value = "ids", required = false) Long[] ids)
{
- List<DocumentMaterials> list;
- System.out.println(ids);
- // 濡傛灉鎻愪緵浜唅ds鍙傛暟锛屽垯鏍规嵁ids瀵煎嚭鎸囧畾璁板綍
- if (ids != null && ids.length > 0) {
- list = documentMaterialsService.selectDocumentMaterialsByIds(ids);
- } else {
- list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials);
- }
- // 鏍规嵁visible瀛楁绛涢�夛紝鍙繚鐣檝isible涓�1鐨勮褰�
- List<DocumentMaterials> filteredList = list.stream()
- .filter(doc -> doc.getVisible() != null && doc.getVisible() == 1 && !Objects.equals(doc.getFileStyle(), "鍏朵粬鏉愭枡"))
- .collect(Collectors.toList());
-
- // 浣跨敤AtomicLong瀹炵幇搴忓彿鐨勯�掑
- AtomicLong nm = new AtomicLong(1L);
- // 灏嗙瓫閫夊悗鐨凞ocumentMaterials杞崲涓篋ocumentMaterialsVo
- List<DocumentMaterialsVoSmall> list1 = filteredList.stream().map(doc -> {
- DocumentMaterialsVoSmall vo = new DocumentMaterialsVoSmall();
- // 鎵嬪姩鏄犲皠瀛楁锛屼娇鐢╣etAndIncrement()鏂规硶鑾峰彇褰撳墠鍊煎苟閫掑
- vo.setNum(nm.getAndIncrement());
+ List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(documentMaterials.getRecordId().toString());
- vo.setDocumentNumber(doc.getDocumentNumber());
- vo.setCreator(doc.getCreator());
- vo.setTitle(doc.getTitle());
- vo.setDate(doc.getDate());
- vo.setPageNumberFormatted(doc.getPageNumber().toString());
- vo.setRemarks(doc.getRemarks());
-// vo.setRecordId(doc.getRecordId() != null ? doc.getRecordId().toString() : null);
-// vo.setPublicity(doc.getPublicity());
- return vo;
- }).collect(Collectors.toList());
+ List<DocumentMaterialsVoSmall> list2 = dsvs.stream().map(res1 -> new DocumentMaterialsVoSmall(res1.getNum(), res1.getDocumentNumber(),res1.getCreator(),
+ res1.getTitle(), res1.getDate(), res1.getPageNumberFormatted(), res1.getRemarks())).collect(Collectors.toList());
+
+// List<DocumentMaterials> list;
+// System.out.println(ids);
+// // 濡傛灉鎻愪緵浜唅ds鍙傛暟锛屽垯鏍规嵁ids瀵煎嚭鎸囧畾璁板綍
+// if (ids != null && ids.length > 0) {
+// list = documentMaterialsService.selectDocumentMaterialsByIds(ids);
+// } else {
+// list = documentMaterialsService.selectDocumentMaterialsList(documentMaterials);
+//
+// }
+// // 鏍规嵁visible瀛楁绛涢�夛紝鍙繚鐣檝isible涓�1鐨勮褰�
+// List<DocumentMaterials> filteredList = list.stream()
+// .filter(doc -> doc.getVisible() != null && doc.getVisible() == 1 && !Objects.equals(doc.getFileStyle(), "鍏朵粬鏉愭枡"))
+// .collect(Collectors.toList());
+//
+// // 浣跨敤AtomicLong瀹炵幇搴忓彿鐨勯�掑
+// AtomicLong nm = new AtomicLong(1L);
+// // 灏嗙瓫閫夊悗鐨凞ocumentMaterials杞崲涓篋ocumentMaterialsVo
+// List<DocumentMaterialsVoSmall> list1 = filteredList.stream().map(doc -> {
+// DocumentMaterialsVoSmall vo = new DocumentMaterialsVoSmall();
+// // 鎵嬪姩鏄犲皠瀛楁锛屼娇鐢╣etAndIncrement()鏂规硶鑾峰彇褰撳墠鍊煎苟閫掑
+// vo.setNum(nm.getAndIncrement());
+//
+// vo.setDocumentNumber(doc.getDocumentNumber());
+// vo.setCreator(doc.getCreator());
+// vo.setTitle(doc.getTitle());
+// vo.setDate(doc.getDate());
+// vo.setPageNumberFormatted(doc.getPageNumber().toString());
+// vo.setRemarks(doc.getRemarks());
+//// vo.setRecordId(doc.getRecordId() != null ? doc.getRecordId().toString() : null);
+//// vo.setPublicity(doc.getPublicity());
+// return vo;
+// }).collect(Collectors.toList());
ExcelUtil<DocumentMaterialsVoSmall> util = new ExcelUtil<DocumentMaterialsVoSmall>(DocumentMaterialsVoSmall.class);
- util.exportExcel(response, list1, "鍗峰唴鐩綍");
+ util.exportExcel(response, list2, "鍗峰唴鐩綍");
}
// List<DocumentMaterialsVo> dsvs = documentMaterialsService.findArchMInfo(id.toString());
@@ -656,4 +668,129 @@
}
+
+ @PostMapping("/uploads/{recordId}")
+ public AjaxResult uploadFiles(List<MultipartFile> files, @PathVariable Long recordId) throws Exception {
+ try {
+ // 涓婁紶鏂囦欢璺緞
+ String filePath = RuoYiConfig.getUploadPath();
+ List<String> urls = new ArrayList<>();
+ List<String> fileNames = new ArrayList<>();
+ List<String> newFileNames = new ArrayList<>();
+ List<String> originalFilenames = new ArrayList<>();
+
+ // 鎵归噺澶勭悊鏂囦欢涓婁紶
+ for (MultipartFile file : files) {
+ // 鏍规嵁鏂囦欢鍚嶇О锛岀劧鍚庝慨鏀瑰搴旀暟鎹殑url
+ String fname = file.getOriginalFilename();
+ if (StringUtils.isBlank(fname)) {
+ continue;
+ }
+
+ // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О
+ String fileName = FileUploadUtils.upload(filePath, file);
+ String url = serverConfig.getUrl() + fileName;
+
+ // 鍒嗗壊鏂囦欢鍚�
+ String[] nams = fname.split("\\.");
+ if (nams.length < 2) {
+ continue;
+ }
+
+ Long nam = Long.parseLong(nams[0]);
+
+ // 鏍规嵁椤靛彿鎷垮埌妗堝嵎鐨勮缁嗕俊鎭�
+ DocumentMaterials doc = documentMaterialsService.selectByPageNumber(nam, Math.toIntExact(recordId));
+ if (doc != null) {
+ if (doc.getSecurityLevel() != null && doc.getSecurityLevel().equals("璇ラ〉鍙﹀瓨")) {
+ // 鏇挎崲涓轰簡鍑嗗濂界殑鍥惧儚
+ String fp = filePath + "\\glc.jpg";
+ Path path = Paths.get(fp);
+ // 鎷垮埌鍥惧儚灞炴��
+ BufferedImage bufferedImage = ImageIO.read(Files.newInputStream(path));
+ int wid = bufferedImage.getWidth();
+ int hei = bufferedImage.getHeight();
+ double sz = Double.parseDouble(String.format("%.2f", Files.size(path) * 1.0 / 1024));
+
+ // 鎷垮埌鍥惧儚鐨刣pi淇℃伅
+ ImageInfo info = Imaging.getImageInfo(Files.readAllBytes(path));
+ int wdpi = info.getPhysicalWidthDpi();
+ int hdpi = info.getPhysicalHeightDpi();
+
+ // 璁$畻fileNumber
+ Long fileNumber = documentMaterialsService.getFiNum(nam, recordId);
+ // 璁$畻sizeType
+ String sizeType = getPageSize(wid * hei);
+
+ Graphics2D g2d = bufferedImage.createGraphics();
+ g2d.setFont(new Font("Arial", Font.BOLD, 80));
+ g2d.setColor(Color.black);
+ String pageNumber = doc.getPageNumber() + "";
+ int fontHeight = g2d.getFontMetrics().getHeight();
+ int x = bufferedImage.getWidth() - g2d.getFontMetrics().stringWidth(pageNumber) - 80;
+ int y = bufferedImage.getHeight() - fontHeight / 2 - 100;
+ g2d.drawString(pageNumber, x, y);
+ g2d.dispose();
+
+ // 灏咮ufferedImage杞崲涓篗ultipartFile
+ MultipartFile multipartFile = null;
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ ImageIO.write(bufferedImage, "jpg", os);
+ InputStream input = new ByteArrayInputStream(os.toByteArray());
+ multipartFile = new MockMultipartFile(pageNumber, pageNumber + ".jpg", "text/plain", input);
+
+ // 涓婁紶骞惰繑鍥炴柊鏂囦欢鍚嶇О
+ String fileName1 = FileUploadUtils.upload(filePath, multipartFile);
+
+ // 鏇存柊鏁版嵁搴�
+ documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber, wid, hei, wdpi, hdpi, sz, fileName1, "jpg", recordId);
+
+ urls.add(serverConfig.getUrl() + fileName1);
+ fileNames.add(fileName1);
+ newFileNames.add(FileUtils.getName(fileName1));
+ originalFilenames.add(pageNumber + ".jpg");
+ } else {
+ // 鏂囦欢鍚嶇О
+ String pname = nams[1];
+
+ // 鎷垮埌鍥惧儚灞炴��
+ BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
+ int wid = bufferedImage.getWidth();
+ int hei = bufferedImage.getHeight();
+ double sz = Double.parseDouble(String.format("%.2f", file.getSize() * 1.0 / 1024));
+
+ // 鎷垮埌鍥惧儚鐨刣pi淇℃伅
+ ImageInfo info = Imaging.getImageInfo(file.getBytes());
+ int wdpi = info.getPhysicalWidthDpi();
+ int hdpi = info.getPhysicalHeightDpi();
+
+ // 璁$畻fileNumber
+ Long fileNumber = documentMaterialsService.getFiNum(nam, recordId);
+ // 璁$畻sizeType
+ String sizeType = getPageSize(wid * hei);
+
+ // 鏇存柊鏁版嵁搴�
+ documentMaterialsService.updateByPageNumber(nam, sizeType, fileNumber, wid, hei, wdpi, hdpi, sz, fileName, pname, recordId);
+
+ urls.add(url);
+ fileNames.add(fileName);
+ newFileNames.add(FileUtils.getName(fileName));
+ originalFilenames.add(fname);
+ }
+ }
+ }
+
+ AjaxResult ajax = AjaxResult.success();
+ ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
+ ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
+ ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
+ ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
+ return ajax;
+ } catch (Exception e) {
+ log.error("鎵归噺涓婁紶鏂囦欢澶辫触", e);
+ return AjaxResult.error(e.getMessage());
+ }
+ }
+
+
}
diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml
index c753da2..d234933 100644
--- a/ruoyi-admin/src/main/resources/application-druid.yml
+++ b/ruoyi-admin/src/main/resources/application-druid.yml
@@ -20,7 +20,7 @@
# 鏈�灏忚繛鎺ユ睜鏁伴噺
minIdle: 10
# 鏈�澶ц繛鎺ユ睜鏁伴噺
- maxActive: 20
+ maxActive: 140
# 閰嶇疆鑾峰彇杩炴帴绛夊緟瓒呮椂鐨勬椂闂�
maxWait: 60000
# 閰嶇疆杩炴帴瓒呮椂鏃堕棿
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index dfbfeb9..3a5d8b9 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -57,9 +57,9 @@
servlet:
multipart:
# 鍗曚釜鏂囦欢澶у皬
- max-file-size: 10MB
+ max-file-size: 200MB
# 璁剧疆鎬讳笂浼犵殑鏂囦欢澶у皬
- max-request-size: 20MB
+ max-request-size: 1000MB
# 鏈嶅姟妯″潡
devtools:
restart:
@@ -134,3 +134,4 @@
excludes: /system/notice
# 鍖归厤閾炬帴
urlPatterns: /system/*,/monitor/*,/tool/*
+
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
index 6ca9169..4c5a8de 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
@@ -12,17 +12,16 @@
import com.ruoyi.common.utils.file.FileTypeUtils;
import com.ruoyi.common.utils.file.ImageUtils;
import com.ruoyi.common.utils.reflect.ReflectUtils;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
-import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
-import org.apache.poi.hssf.usermodel.HSSFDataValidation;
-import org.apache.poi.hssf.usermodel.HSSFRichTextString;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
-import org.apache.poi.hssf.usermodel.HSSFDataValidation;
-import org.apache.poi.hssf.usermodel.HSSFRichTextString;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDataValidation;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -260,8 +259,11 @@
* @throws IOException
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName) throws IOException {
- response.setContentType("application/vnd.ms-excel");
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
+ // 璁剧疆鏂囦欢鍚�
+ String fileName = UUID.randomUUID() + "_" + ".xlsx";
+ response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
this.init(list, sheetName, Excel.Type.EXPORT);
exportExcel(response.getOutputStream());
}
@@ -274,10 +276,21 @@
* @return 缁撴灉
* @throws IOException
*/
+ /**
+ * 瀵筶ist鏁版嵁婧愬皢鍏堕噷闈㈢殑鏁版嵁瀵煎叆鍒癳xcel琛ㄥ崟
+ *
+ * @param response 杩斿洖鏁版嵁
+ * @param list 瀵煎嚭鏁版嵁闆嗗悎
+ * @return 缁撴灉
+ * @throws IOException
+ */
public void exportExcelManySheet(HttpServletResponse response, List<ExcelExp> list, boolean includeQrCode, byte[] bt,
List<String> sigArr, List<String> arrAn, String inquiryNumber, String caseTitle) throws IOException {
- // response.setContentType("application/vnd.ms-excel");
- // response.setCharacterEncoding("utf-8");
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ response.setCharacterEncoding("utf-8");
+ // 璁剧疆鏂囦欢鍚�
+ String fileName = UUID.randomUUID() + "_" + ".xlsx";
+ response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
try {
createWorkbook();
@@ -296,18 +309,33 @@
// 鍚堝苟绗竴琛岀殑鍓�5涓崟鍏冩牸
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 8));
+ // 蹇呴』鍏堣缃负true
+ // 椤甸潰甯冨眬璁剧疆
+ sheet.setAutobreaks(true);
+ sheet.setFitToPage(true);
+
+ // 鑾峰彇鎵撳嵃璁剧疆
+ PrintSetup printSetup = sheet.getPrintSetup();
+
+ // 璁剧疆涓�1椤靛搴�
+ printSetup.setFitWidth((short) 1); // 瀹藉害璋冩暣涓�1椤�
+ printSetup.setFitHeight((short) 0); // 楂樺害涓嶉檺鍒�
+
+ // 鍏朵粬鎵撳嵃璁剧疆
+ printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); // A4绾�
+ printSetup.setLandscape(false); // 绾靛悜鎵撳嵃
// 鍒涘缓琛屽苟璁剧疆楂樺害
- row = sheet.createRow(firow);
- row.setHeight((short)(40 * 40));
+ row = sheet.createRow(firow);
//鐢熸垚浜岀淮鐮�
if(includeQrCode)
{
- Cell cell = row.createCell(6);
+ row.setHeight((short)(40 * 40));
+ Cell cell = row.createCell(6);
// 璁剧疆鍥剧墖澶у皬鍜屼綅缃�
- ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2),
+ ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2),
cell.getRow().getRowNum() + 1);
// 璁$畻灞呬腑浣嶇疆
// int col1 = 0; // 涓棿鍒�
@@ -318,20 +346,23 @@
// anchor.setDy1(0);
// anchor.setDx2(255); // 瀹藉害
// anchor.setDy2(255); // 楂樺害
- anchor.setRow1(1);
+ anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
+ // 璁$畻灞呬腑浣嶇疆
+ int col1 = 3; // 涓棿鍒�
+ int col2 = col1 + 3;
+ anchor.setCol1(col1);
+ anchor.setCol2(col2);
+ anchor.setRow1(0);
anchor.setRow2(1);
byte[] data = bt;
- anchor.setDx1(2400000);
- anchor.setDy1(-10);
-
- anchor.setDy2(-800000);
+
// 鑾峰彇鍥剧墖鍘熷灏哄
BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
double widthInEMU = image.getWidth() * 9525 * 0.2;
double heightInEMU = image.getHeight() * 9525;
// 璁剧疆鍥剧墖鍘熷灏哄
- anchor.setDx2(-100000); // 鍘熷瀹藉害
+ // anchor.setDx2(-100000); // 鍘熷瀹藉害
// anchor.setDy2((int)heightInEMU); // 鍘熷楂樺害
//anchor.setCol1(5); // 浠庣6鍒楀紑濮嬫樉绀�
//anchor.setCol2(10); // 鍒扮11鍒楃粨鏉�
@@ -345,6 +376,9 @@
firow = firow + 1;
row = sheet.createRow(firow);
}
+ else
+ row.setHeight((short)(20 * 20));
+
// sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));
if(firow==1)
{
@@ -364,16 +398,67 @@
titleCell.setCellStyle(style);
firow = firow + 1;
row = sheet.createRow(firow);
+ // 灏嗗浐瀹氳楂樻敼涓鸿嚜鍔ㄨ楂橈紝浠ヤ究鍐呭鑳藉畬鏁存樉绀哄湪鍚堝苟鍖哄煙
+ row.setHeight((short)(50*20));
//
- row.createCell(0).setCellValue("鍙戞枃鍙�:");
- sheet.addMergedRegion(new CellRangeAddress(firow, firow, 1, 3));
- row.createCell(1).setCellValue(inquiryNumber);
- row.createCell(4).setCellValue("妗堝嵎棰樺悕:");
- sheet.addMergedRegion(new CellRangeAddress(firow, firow, 5, 9));
+ CellStyle style1 = wb.createCellStyle();
+ style1.setAlignment(HorizontalAlignment.LEFT);
+ Cell cell2 = row.createCell(0);
+ cell2.setCellValue("鍙戞枃鍙�:");
+ cell2.setCellStyle(style1);
+
+ // 鍚堝苟绗�1-3鍒�
+ int startCol1 = 1;
+ int endCol1 = 3;
+ sheet.addMergedRegion(new CellRangeAddress(firow, firow, startCol1, endCol1));
+
+ // 璁剧疆鎵�鏈夊悎骞跺崟鍏冩牸鐨勬牱寮�
+ for (int col = startCol1; col <= endCol1; col++) {
+ Cell mergedCell = row.createCell(col);
+ mergedCell.setCellStyle(style1);
+ }
+
+ // 鍙湪璧峰鍗曞厓鏍艰缃暟鎹�
+ Cell inquiryCell = row.getCell(startCol1);
+ inquiryCell.setCellValue(inquiryNumber);
+ Cell cell1 = row.createCell(4);
+ cell1.setCellValue("妗堝嵎棰樺悕:");
+ cell1.setCellStyle(style1);
+
+ // 鍒涘缓涓�涓柊鐨勬牱寮忕敤浜庢鍗烽鍚嶅悎骞跺崟鍏冩牸
+ CellStyle mergedCellStyle = wb.createCellStyle();
+ mergedCellStyle.cloneStyleFrom(style1); // 缁ф壙鍘熸湁鏍峰紡
+ mergedCellStyle.setAlignment(HorizontalAlignment.LEFT); // 鏀逛负宸﹀榻�
+ mergedCellStyle.setWrapText(true); // 鍚敤鑷姩鎹㈣
+ //mergedCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 鍨傜洿灞呬腑
+
+ // 鍚堝苟绗�5-8鍒�
+ int startCol = 5;
+ int endCol = 8;
+
+ // 鍏堝垱寤烘墍鏈夐渶瑕佺殑鍗曞厓鏍煎苟璁剧疆鏍峰紡
+ for (int col = startCol; col <= endCol; col++) {
+ Cell mergedCell = row.createCell(col);
+ mergedCell.setCellStyle(mergedCellStyle);
+ }
+
+ // 鐒跺悗鎵ц鍚堝苟鎿嶄綔
+ sheet.addMergedRegion(new CellRangeAddress(firow, firow, startCol, endCol));
- // row.createCell(4).setCellValue("妗e彿:");
- //鎷垮埌妗e彿
- row.createCell(5).setCellValue(caseTitle);
+ // 鍙湪璧峰鍗曞厓鏍艰缃暟鎹�
+ Cell getCas = row.getCell(startCol);
+ getCas.setCellStyle(mergedCellStyle);
+ getCas.setCellValue(caseTitle);
+ // 鍙湪璧峰鍗曞厓鏍艰缃暟鎹�
+ //ces.setCellValue(caseTitle);
+
+ // 璁剧疆鑷姩鎹㈣
+// row = sheet.createRow(2);
+// row.createCell(0).setCellValue("妗堝嵎棰樺悕:");
+
+
+
+ // 璁剧疆鑷姩鎹㈣
// row = sheet.createRow(2);
// row.createCell(0).setCellValue("妗堝嵎棰樺悕:");
firow = firow + 1;
@@ -383,7 +468,7 @@
column = 0;
} else {
// 鏅�歴heet澶勭悊
- // recordId = (DocumentMaterialsVo)list.get(0)
+ // recordId = (DocumentMaterialsVo)list.get(0)
row = sheet.createRow(0);
column = 0;
}
@@ -447,8 +532,11 @@
* @return 缁撴灉
*/
public void importTemplateExcel(HttpServletResponse response, String sheetName) throws IOException {
- response.setContentType("application/vnd.ms-excel");
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
+ // 璁剧疆鏂囦欢鍚�
+ String fileName = UUID.randomUUID() + "_" + ".xlsx";
+ response.setHeader("Content-Disposition", "attachment; filename=" );
this.init(null, sheetName, Excel.Type.IMPORT);
exportExcel(response.getOutputStream());
}
@@ -562,7 +650,7 @@
String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
if (!headerStyles.containsKey(key))
{
- style = wb.createCellStyle();
+ style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
@@ -647,7 +735,7 @@
} else if (Excel.ColumnType.NUMERIC == attr.cellType()) {
cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
} else if (Excel.ColumnType.IMAGE == attr.cellType()) {
- ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
+ ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
cell.getRow().getRowNum() + 1);
String imagePath = Convert.toStr(value);
if (StringUtils.isNotEmpty(imagePath)) {
@@ -694,12 +782,12 @@
// 濡傛灉璁剧疆浜嗘彁绀轰俊鎭垯榧犳爣鏀句笂鍘绘彁绀�.
if (StringUtils.isNotEmpty(attr.prompt())) {
// 杩欓噷榛樿璁句簡2-101鍒楁彁绀�.
- setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
+ setCellPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
}
// 濡傛灉璁剧疆浜哻ombo灞炴�у垯鏈垪鍙兘閫夋嫨涓嶈兘杈撳叆
if (attr.combo().length > 0) {
// 杩欓噷榛樿璁句簡2-101鍒楀彧鑳介�夋嫨涓嶈兘杈撳叆.
- setHSSFValidation(sheet, attr.combo(), 1, 100, column, column);
+ setCellValidation(sheet, attr.combo(), 1, 100, column, column);
}
}
@@ -751,7 +839,7 @@
}
/**
- * 璁剧疆 POI HSSFSheet 鍗曞厓鏍兼彁绀�
+ * 璁剧疆鍗曞厓鏍兼彁绀�
*
* @param sheet 琛ㄥ崟
* @param promptTitle 鎻愮ず鏍囬
@@ -761,7 +849,7 @@
* @param firstCol 寮�濮嬪垪
* @param endCol 缁撴潫鍒�
*/
- public void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
+ public void setCellPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = helper.createCustomConstraint("DD1");
@@ -783,7 +871,7 @@
* @param endCol 缁撴潫鍒�
* @return 璁剧疆濂界殑sheet.
*/
- public void setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
+ public void setCellValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
// 鍔犺浇涓嬫媺鍒楄〃鍐呭
DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist);
@@ -792,7 +880,7 @@
// 鏁版嵁鏈夋晥鎬у璞�
DataValidation dataValidation = helper.createValidation(constraint, regions);
// 澶勭悊Excel鍏煎鎬ч棶棰�
- if (dataValidation instanceof HSSFDataValidation) {
+ if (dataValidation instanceof XSSFDataValidation) {
dataValidation.setSuppressDropDownArrow(false);
dataValidation.setShowErrorBox(true);
}
@@ -991,7 +1079,7 @@
* 鍒涘缓涓�涓伐浣滅翱
*/
public void createWorkbook() {
- this.wb = new HSSFWorkbook();
+ this.wb = new XSSFWorkbook();
}
/**
@@ -1060,4 +1148,18 @@
}
return val;
}
-}
\ No newline at end of file
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--
Gitblit v1.9.1