|
@@ -1,27 +1,20 @@
|
|
|
package org.springblade.manager.controller;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.aspose.cells.Worksheet;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
import io.swagger.annotations.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import org.apache.commons.codec.Charsets;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
-import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
-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.jsoup.select.Selector;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
-import org.springblade.core.tool.utils.IoUtil;
|
|
|
import org.springblade.manager.dto.WbsTreeContractDTO2;
|
|
|
import org.springblade.manager.entity.ContractInfo;
|
|
|
import org.springblade.manager.entity.ExcelTab;
|
|
@@ -39,14 +32,13 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@AllArgsConstructor
|
|
@@ -60,7 +52,6 @@ public class WbsTreeContractController extends BladeController {
|
|
|
private final IWbsTreeContractService iWbsTreeContractService;
|
|
|
private final WbsTreeContractServiceImpl wbsTreeContractServiceImpl;
|
|
|
private final ContractClient contractClient;
|
|
|
- private final ExcelTabController excelTabController;
|
|
|
|
|
|
@GetMapping("/search-node-tables")
|
|
|
@ApiOperationSupport(order = 1)
|
|
@@ -256,23 +247,21 @@ public class WbsTreeContractController extends BladeController {
|
|
|
if (tab != null && Objects.nonNull(tab.getExcelId())) {
|
|
|
ExcelTab excelTab = jdbcTemplate.queryForObject("select file_url,name from m_excel_tab where id = " + tab.getExcelId(), new BeanPropertyRowMapper<>(ExcelTab.class));
|
|
|
if (excelTab != null) {
|
|
|
- InputStream ossInputStream = CommonUtil.getOSSInputStream(excelTab.getFileUrl());
|
|
|
- Workbook workbook = parseExcelFile(ossInputStream);
|
|
|
- String fileName = new String(excelTab.getName().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
|
|
|
- response.setContentType("application/vnd.ms-excel");
|
|
|
- response.setCharacterEncoding("UTF-8");
|
|
|
- response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + ".xlsx\"");
|
|
|
- try (OutputStream toClient = new BufferedOutputStream(response.getOutputStream())) {
|
|
|
- workbook.write(toClient);
|
|
|
- toClient.flush();
|
|
|
- } finally {
|
|
|
- workbook.close();
|
|
|
+ InputStream inputStream = CommonUtil.getOSSInputStream(excelTab.getFileUrl());
|
|
|
+ try (Workbook workbook = parseExcelFile(inputStream)) {
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setHeader("Content-disposition", ";filename=" + URLEncoder.encode(excelTab.getName().replace(" ", ""), "UTF-8") + ".xlsx");
|
|
|
+ ServletOutputStream servletOutputStream = response.getOutputStream();
|
|
|
+ workbook.write(servletOutputStream);
|
|
|
+ servletOutputStream.flush();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//解析Excel文件并设置单元格格式为文本
|
|
|
private Workbook parseExcelFile(InputStream inputStream) throws IOException, InvalidFormatException {
|
|
|
Workbook workbook = WorkbookFactory.create(inputStream);
|