fix(企标宣贯): 79573
This commit is contained in:
-2
@@ -368,8 +368,6 @@ public class LawsCustomCompareInfoServiceImpl extends ServiceImpl<LawsCustomComp
|
|||||||
// 获取单元格内容
|
// 获取单元格内容
|
||||||
List<LawsCustomCompareCell> list = tableDetailVO.getList();
|
List<LawsCustomCompareCell> list = tableDetailVO.getList();
|
||||||
|
|
||||||
|
|
||||||
// Workbook workbook = new XSSFWorkbook()
|
|
||||||
try (Workbook workbook = new HSSFWorkbook()){
|
try (Workbook workbook = new HSSFWorkbook()){
|
||||||
String fileName = "清单详情.xls";
|
String fileName = "清单详情.xls";
|
||||||
// sheet页
|
// sheet页
|
||||||
|
|||||||
+12
-2
@@ -16,7 +16,9 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,11 +60,19 @@ public class EnterpriseStandardDeclareController extends JeroController<Enterpri
|
|||||||
esDeclareService.export(response, esQueryCommonDTO, "企标宣贯", "企标宣贯");
|
esDeclareService.export(response, esQueryCommonDTO, "企标宣贯", "企标宣贯");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @RequiresPermissions("enterpriseStandardLibrary:publicize:fileExport")
|
||||||
|
// @AutoLog(value = "企标宣贯-带文件导出")
|
||||||
|
// @ApiOperation(value="企标宣贯-带文件导出", notes="企标宣贯-带文件导出")
|
||||||
|
// @GetMapping("/exportDataWithFile")
|
||||||
|
// public void exportDataWithFile(HttpServletResponse response, ESQueryCommonDTO esQueryCommonDTO) {
|
||||||
|
// esDeclareService.exportDataWithFile(response, esQueryCommonDTO, "企标宣贯", "企标宣贯");
|
||||||
|
// }
|
||||||
|
|
||||||
@RequiresPermissions("enterpriseStandardLibrary:publicize:fileExport")
|
@RequiresPermissions("enterpriseStandardLibrary:publicize:fileExport")
|
||||||
@AutoLog(value = "企标宣贯-带文件导出")
|
@AutoLog(value = "企标宣贯-带文件导出")
|
||||||
@ApiOperation(value="企标宣贯-带文件导出", notes="企标宣贯-带文件导出")
|
@ApiOperation(value="企标宣贯-带文件导出", notes="企标宣贯-带文件导出")
|
||||||
@GetMapping("/exportDataWithFile")
|
@GetMapping("/exportDataWithFile")
|
||||||
public void exportDataWithFile(HttpServletResponse response, ESQueryCommonDTO esQueryCommonDTO) {
|
public void exportDataWithFile(HttpServletRequest request, HttpServletResponse response, ESQueryCommonDTO esQueryCommonDTO) throws IOException {
|
||||||
esDeclareService.exportDataWithFile(response, esQueryCommonDTO, "企标宣贯", "企标宣贯");
|
esDeclareService.exportDataWithFile(request, response, esQueryCommonDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.jero.modules.laws.enterprise.entity.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: DeclareFileList
|
||||||
|
* @Description:
|
||||||
|
* @Author: yjz
|
||||||
|
* @Date: 2023-12-27 15:20
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
public class DeclareFileList {
|
||||||
|
@ApiModelProperty(value = "id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Excel(name = "相关材料", width = 15)
|
||||||
|
@ApiModelProperty(value = "相关材料文件名")
|
||||||
|
private String fileName;
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package com.jero.modules.laws.enterprise.entity.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||||
|
import org.jeecgframework.poi.excel.annotation.ExcelCollection;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: EnterpriseStandardDeclareExcel
|
||||||
|
* @Description: 企标宣贯-带文件导出
|
||||||
|
* @Author: yjz
|
||||||
|
* @Date: 2023-12-27 15:18
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
public class EnterpriseStandardDeclareExcel {
|
||||||
|
@ApiModelProperty(value = "主键id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Excel(name = "企标编号", width = 15, needMerge = true)
|
||||||
|
@ApiModelProperty(value = "企标编号")
|
||||||
|
private String standardNo;
|
||||||
|
|
||||||
|
@Excel(name = "企标名称", width = 15, needMerge = true)
|
||||||
|
@ApiModelProperty(value = "企标名称")
|
||||||
|
private String standardName;
|
||||||
|
|
||||||
|
@Excel(name = "发布日期", width = 15, format = "yyyy-MM-dd", needMerge = true)
|
||||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||||
|
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||||
|
@ApiModelProperty(value = "发布日期")
|
||||||
|
private Date releaseDate;
|
||||||
|
|
||||||
|
@Excel(name = "实施日期", width = 15, format = "yyyy-MM-dd", needMerge = true)
|
||||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||||
|
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||||
|
@ApiModelProperty(value = "实施日期")
|
||||||
|
private Date implementationDate;
|
||||||
|
|
||||||
|
@Excel(name = "宣贯日期", width = 15, format = "yyyy-MM-dd", needMerge = true)
|
||||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||||
|
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||||
|
@ApiModelProperty(value = "宣贯日期")
|
||||||
|
private Date declareDate;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "宣贯人id")
|
||||||
|
private String declareUser;
|
||||||
|
|
||||||
|
@Excel(name = "宣贯人姓名", width = 15, needMerge = true)
|
||||||
|
@ApiModelProperty(value = "宣贯人姓名")
|
||||||
|
private String declareUserName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "相关材料id")
|
||||||
|
private String declareFile;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "相关材料文件名")
|
||||||
|
@ExcelCollection(name = "")
|
||||||
|
private List<DeclareFileList> declareFileList = Collections.emptyList();
|
||||||
|
}
|
||||||
+9
@@ -7,6 +7,8 @@ import com.jero.modules.laws.enterprise.entity.dto.ESQueryCommonDTO;
|
|||||||
import com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareVo;
|
import com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareVo;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ThinkBook
|
* @author ThinkBook
|
||||||
* @description 针对表【laws_enterprise_standard_declare】的数据库操作Mapper
|
* @description 针对表【laws_enterprise_standard_declare】的数据库操作Mapper
|
||||||
@@ -22,6 +24,13 @@ public interface EnterpriseStandardDeclareMapper extends BaseMapper<EnterpriseSt
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IPage<EnterpriseStandardDeclareVo> page(IPage<EnterpriseStandardDeclareVo> page, @Param("param") ESQueryCommonDTO esDeclare);
|
IPage<EnterpriseStandardDeclareVo> page(IPage<EnterpriseStandardDeclareVo> page, @Param("param") ESQueryCommonDTO esDeclare);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 宣贯列表
|
||||||
|
* @param esDeclare
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<EnterpriseStandardDeclareVo> list(@Param("param") ESQueryCommonDTO esDeclare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+22
-14
@@ -29,20 +29,28 @@
|
|||||||
|
|
||||||
|
|
||||||
<select id="page" resultType="com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareVo">
|
<select id="page" resultType="com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareVo">
|
||||||
|
<include refid="select_laws_enterprise_standard_declare"/>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="list" resultType="com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareVo">
|
||||||
|
<include refid="select_laws_enterprise_standard_declare"/>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<sql id="select_laws_enterprise_standard_declare">
|
||||||
SELECT
|
SELECT
|
||||||
d.id,
|
d.id,
|
||||||
s.standard_number AS standardNo,
|
s.standard_number AS standardNo,
|
||||||
s.standard_name,
|
s.standard_name,
|
||||||
s.release_date,
|
s.release_date,
|
||||||
s.implementation_date,
|
s.implementation_date,
|
||||||
d.declare_date,
|
d.declare_date,
|
||||||
d.declare_user,
|
d.declare_user,
|
||||||
CONCAT(u.realname, '(', u.username, ')') AS declareUserName,
|
CONCAT(u.realname, '(', u.username, ')') AS declareUserName,
|
||||||
d.declare_file
|
d.declare_file
|
||||||
FROM
|
FROM
|
||||||
`laws_enterprise_standard_declare` AS d
|
`laws_enterprise_standard_declare` AS d
|
||||||
LEFT JOIN laws_enterprise_standard AS s ON d.standard_id = s.id
|
LEFT JOIN laws_enterprise_standard AS s ON d.standard_id = s.id
|
||||||
LEFT JOIN sys_user AS u ON u.id = d.declare_user
|
LEFT JOIN sys_user AS u ON u.id = d.declare_user
|
||||||
Where 1 = 1
|
Where 1 = 1
|
||||||
<!--企标编号判断-->
|
<!--企标编号判断-->
|
||||||
<if test="param.standardNo != null and param.standardNo != ''">
|
<if test="param.standardNo != null and param.standardNo != ''">
|
||||||
@@ -67,6 +75,6 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
ORDER BY
|
ORDER BY
|
||||||
d.create_time DESC
|
d.create_time DESC
|
||||||
</select>
|
</sql>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
+5
-2
@@ -1,13 +1,14 @@
|
|||||||
package com.jero.modules.laws.enterprise.service;
|
package com.jero.modules.laws.enterprise.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardDeclare;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardDeclare;
|
||||||
import com.jero.modules.laws.enterprise.entity.dto.ESQueryCommonDTO;
|
import com.jero.modules.laws.enterprise.entity.dto.ESQueryCommonDTO;
|
||||||
import com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareVo;
|
import com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareVo;
|
||||||
import com.jero.modules.oss.entity.OSSFile;
|
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ThinkBook
|
* @author ThinkBook
|
||||||
@@ -42,4 +43,6 @@ public interface EnterpriseStandardDeclareService extends IService<EnterpriseSta
|
|||||||
* @param sheetName
|
* @param sheetName
|
||||||
*/
|
*/
|
||||||
void exportDataWithFile(HttpServletResponse response, ESQueryCommonDTO parameterMap, String fileName, String sheetName);
|
void exportDataWithFile(HttpServletResponse response, ESQueryCommonDTO parameterMap, String fileName, String sheetName);
|
||||||
|
|
||||||
|
void exportDataWithFile(HttpServletRequest request, HttpServletResponse response, ESQueryCommonDTO parameterMap) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
+142
-5
@@ -4,30 +4,42 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.jero.common.exception.JeroBootException;
|
|
||||||
import com.jero.common.util.MessageUtils;
|
|
||||||
import com.jero.common.api.vo.ResultCommon;
|
import com.jero.common.api.vo.ResultCommon;
|
||||||
|
import com.jero.common.exception.JeroBootException;
|
||||||
|
import com.jero.common.util.FileUtils;
|
||||||
|
import com.jero.common.util.MessageUtils;
|
||||||
|
import com.jero.common.util.MinioUtil;
|
||||||
|
import com.jero.common.util.ZipUtil;
|
||||||
import com.jero.modules.laws.common.service.ILawsCommonService;
|
import com.jero.modules.laws.common.service.ILawsCommonService;
|
||||||
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardDeclare;
|
import com.jero.modules.laws.enterprise.entity.EnterpriseStandardDeclare;
|
||||||
import com.jero.modules.laws.enterprise.entity.dto.ESQueryCommonDTO;
|
import com.jero.modules.laws.enterprise.entity.dto.ESQueryCommonDTO;
|
||||||
import com.jero.modules.laws.enterprise.entity.dto.EnterpriseStandardDeclareExPortDto;
|
import com.jero.modules.laws.enterprise.entity.dto.EnterpriseStandardDeclareExPortDto;
|
||||||
|
import com.jero.modules.laws.enterprise.entity.vo.DeclareFileList;
|
||||||
|
import com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareExcel;
|
||||||
import com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareVo;
|
import com.jero.modules.laws.enterprise.entity.vo.EnterpriseStandardDeclareVo;
|
||||||
import com.jero.modules.laws.enterprise.service.EnterpriseStandardDeclareService;
|
|
||||||
import com.jero.modules.laws.enterprise.mapper.EnterpriseStandardDeclareMapper;
|
import com.jero.modules.laws.enterprise.mapper.EnterpriseStandardDeclareMapper;
|
||||||
|
import com.jero.modules.laws.enterprise.service.EnterpriseStandardDeclareService;
|
||||||
import com.jero.modules.laws.enterprise.util.BeanCopyUtils;
|
import com.jero.modules.laws.enterprise.util.BeanCopyUtils;
|
||||||
|
import com.jero.modules.laws.enterprise.util.WaterMarkUtil;
|
||||||
import com.jero.modules.oss.entity.OSSFile;
|
import com.jero.modules.oss.entity.OSSFile;
|
||||||
import com.jero.modules.oss.service.IOSSFileService;
|
import com.jero.modules.oss.service.IOSSFileService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||||
|
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.*;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -53,6 +65,13 @@ public class EnterpriseStandardDeclareServiceImpl extends ServiceImpl<Enterprise
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ILawsCommonService lawsCommonService;
|
private ILawsCommonService lawsCommonService;
|
||||||
|
@Resource
|
||||||
|
private WaterMarkUtil waterMarkUtil;
|
||||||
|
|
||||||
|
@Value("${jero.path.exportExcelTempPath}")
|
||||||
|
private String exportExcelTempPath;
|
||||||
|
|
||||||
|
private static final String EXPORT_EXCEL_TEMP = "exportExcelTemp";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<EnterpriseStandardDeclareVo> queryPageList(ESQueryCommonDTO esDeclare, Integer pageNo, Integer pageSize) {
|
public IPage<EnterpriseStandardDeclareVo> queryPageList(ESQueryCommonDTO esDeclare, Integer pageNo, Integer pageSize) {
|
||||||
@@ -144,6 +163,9 @@ public class EnterpriseStandardDeclareServiceImpl extends ServiceImpl<Enterprise
|
|||||||
// 将文件和文件夹加入ZIP
|
// 将文件和文件夹加入ZIP
|
||||||
for (EnterpriseStandardDeclareVo vo : records) {
|
for (EnterpriseStandardDeclareVo vo : records) {
|
||||||
OSSFile ossFile = ossFileMap.get(vo.getDeclareFile());
|
OSSFile ossFile = ossFileMap.get(vo.getDeclareFile());
|
||||||
|
if (Objects.isNull(ossFile) || StringUtils.isBlank(vo.getDeclareFile()) || StringUtils.isBlank(vo.getDeclareFileName())){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ZipEntry fileEntry = new ZipEntry(vo.getDeclareFileName());
|
ZipEntry fileEntry = new ZipEntry(vo.getDeclareFileName());
|
||||||
zipOut.putNextEntry(fileEntry);
|
zipOut.putNextEntry(fileEntry);
|
||||||
|
|
||||||
@@ -159,13 +181,128 @@ public class EnterpriseStandardDeclareServiceImpl extends ServiceImpl<Enterprise
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exportDataWithFile(HttpServletRequest request, HttpServletResponse response, ESQueryCommonDTO parameterMap) throws IOException {
|
||||||
|
String fileName = "企标宣贯";
|
||||||
|
String url = exportExcelTempPath.replace(EXPORT_EXCEL_TEMP, fileName);
|
||||||
|
File file = new File(url);
|
||||||
|
if (!file.exists()){
|
||||||
|
boolean mkdirs = file.mkdirs();
|
||||||
|
log.info("创建临时目录:{}", mkdirs);
|
||||||
|
}
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(url + File.separator + fileName + ".xls")){
|
||||||
|
// 查询数据
|
||||||
|
List<EnterpriseStandardDeclareVo> list = esDeclareMapper.list(parameterMap);
|
||||||
|
// 过滤勾选数据
|
||||||
|
if (StringUtils.isNotBlank(parameterMap.getSelections())){
|
||||||
|
List<String> selections = Arrays.asList(parameterMap.getSelections().split(","));
|
||||||
|
list = list.stream().filter(v -> selections.contains(v.getId())).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
// 构建一对多关系
|
||||||
|
List<EnterpriseStandardDeclareExcel> enterpriseStandardDeclareExcels = com.jero.common.util.BeanCopyUtils.copyBeanList(list, EnterpriseStandardDeclareExcel.class);
|
||||||
|
List<EnterpriseStandardDeclareExcel> newEnterpriseStandardDeclareExcels = new ArrayList<>(enterpriseStandardDeclareExcels);
|
||||||
|
// 处理文件
|
||||||
|
settleDocuments(url, enterpriseStandardDeclareExcels);
|
||||||
|
|
||||||
|
// 生成excel
|
||||||
|
ExportParams exportParams = new ExportParams();
|
||||||
|
exportParams.setType(ExcelType.HSSF);
|
||||||
|
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, EnterpriseStandardDeclareExcel.class, enterpriseStandardDeclareExcels);
|
||||||
|
// 生成超链接
|
||||||
|
generateHyperlink(newEnterpriseStandardDeclareExcels, workbook);
|
||||||
|
// 导出excel
|
||||||
|
workbook.write(fos);
|
||||||
|
// 生成并导出zip
|
||||||
|
ZipUtil.toZip(url, response.getOutputStream(), response, true);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage());
|
||||||
|
throw new JeroBootException("excel导出失败!");
|
||||||
|
}finally {
|
||||||
|
// 删除文件
|
||||||
|
if (new File(url).exists()) {
|
||||||
|
FileUtils.deleteFolders(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void generateHyperlink(List<EnterpriseStandardDeclareExcel> newEnterpriseStandardDeclareExcels, Workbook workbook) {
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
int i = 1;
|
||||||
|
for (EnterpriseStandardDeclareExcel enterpriseStandardDeclareExcel : newEnterpriseStandardDeclareExcels) {
|
||||||
|
if (!Objects.isNull(enterpriseStandardDeclareExcel.getDeclareFileList()) && !enterpriseStandardDeclareExcel.getDeclareFileList().isEmpty()){
|
||||||
|
for (DeclareFileList declareFileList : enterpriseStandardDeclareExcel.getDeclareFileList()) {
|
||||||
|
Row row = sheet.getRow(i);
|
||||||
|
Cell cell = row.getCell(6);
|
||||||
|
cell.setCellFormula("HYPERLINK(\"" + ".\\" + declareFileList.getFileName() + "\")");
|
||||||
|
cell.setCellValue(declareFileList.getFileName());
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void settleDocuments(String url, List<EnterpriseStandardDeclareExcel> enterpriseStandardDeclareExcels) throws IOException {
|
||||||
|
for (EnterpriseStandardDeclareExcel enterpriseStandardDeclareExcel : enterpriseStandardDeclareExcels) {
|
||||||
|
// 查询文件
|
||||||
|
if (StringUtils.isNotBlank(enterpriseStandardDeclareExcel.getDeclareFile())){
|
||||||
|
List<String> fileIdList = Arrays.asList(enterpriseStandardDeclareExcel.getDeclareFile().split(","));
|
||||||
|
List<OSSFile> ossFileList = ossFileService.listByIds(fileIdList);
|
||||||
|
if (!ossFileList.isEmpty()){
|
||||||
|
// 赋值
|
||||||
|
List<DeclareFileList> declareFileLists = com.jero.common.util.BeanCopyUtils.copyBeanList(ossFileList, DeclareFileList.class);
|
||||||
|
enterpriseStandardDeclareExcel.setDeclareFileList(declareFileLists);
|
||||||
|
// 写出文件
|
||||||
|
for (OSSFile ossFile : ossFileList) {
|
||||||
|
InputStream inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), ossFile.getUrl());
|
||||||
|
// pdf加水印
|
||||||
|
if (StringUtils.endsWithIgnoreCase(ossFile.getFileName(), ".pdf")){
|
||||||
|
inputStream = waterMarkUtil.addWatermarkToPdf(inputStream);
|
||||||
|
}
|
||||||
|
// 导出文件
|
||||||
|
String filePath = url + File.separator + ossFile.getFileName();
|
||||||
|
writeToLocal(filePath, inputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将InputStream写入本地文件
|
||||||
|
*
|
||||||
|
* @param destination 写入本地目录
|
||||||
|
* @param input 输入流
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private static void writeToLocal(String destination, InputStream input)
|
||||||
|
throws IOException {
|
||||||
|
int index;
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
try (FileOutputStream downloadFile = new FileOutputStream(destination)){
|
||||||
|
while ((index = input.read(bytes)) != -1) {
|
||||||
|
downloadFile.write(bytes, 0, index);
|
||||||
|
downloadFile.flush();
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("将InputStream写入本地失败:{}", e.getMessage());
|
||||||
|
}finally {
|
||||||
|
input.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置导出的Excel中的相关文件字段
|
* 设置导出的Excel中的相关文件字段
|
||||||
* @param records
|
* @param records
|
||||||
*/
|
*/
|
||||||
private void setRecordFile(List<EnterpriseStandardDeclareVo> records) {
|
private void setRecordFile(List<EnterpriseStandardDeclareVo> records) {
|
||||||
records.forEach(record -> record.setDeclareFileName(record.getStandardNo().replace("/", "_") + "/" + record.getDeclareFileName()));
|
for (EnterpriseStandardDeclareVo enterpriseStandardDeclareVo : records) {
|
||||||
|
if (StringUtils.isBlank(enterpriseStandardDeclareVo.getDeclareFile())){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
enterpriseStandardDeclareVo.setDeclareFileName(enterpriseStandardDeclareVo.getStandardNo().replace("/", "_") + "/" + enterpriseStandardDeclareVo.getDeclareFileName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user