Merge branch 'caihaohan' into lixuetao
# Conflicts: # adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java
This commit is contained in:
+65
-15
@@ -1,12 +1,9 @@
|
||||
package com.adc.da.report.controller;
|
||||
|
||||
import com.adc.da.login.util.UserUtils;
|
||||
import com.adc.da.report.annotation.ReportLog;
|
||||
import com.adc.da.report.dao.mysql.ReportDao;
|
||||
import com.adc.da.report.dao.mysql.ReportLogBookDao;
|
||||
import com.adc.da.report.eo.FileEntity;
|
||||
import com.adc.da.report.eo.ReportEntity;
|
||||
import com.adc.da.report.eo.ReportLogBook;
|
||||
import com.adc.da.report.service.IFileService;
|
||||
import com.adc.da.report.service.IReportService;
|
||||
import com.adc.da.report.util.LocalFileUtil;
|
||||
@@ -16,7 +13,6 @@ import com.adc.da.report.vo.ReportQueryVo;
|
||||
import com.adc.da.report.vo.ReportVo;
|
||||
import com.adc.da.util.http.ResponseMessage;
|
||||
import com.adc.da.util.http.Result;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -80,6 +76,9 @@ public class ReportManageConroller {
|
||||
|
||||
@Autowired
|
||||
private ReportLogBookDao reportLogBookDao;
|
||||
@Resource
|
||||
private WaterMarkUtil waterMarkUtil;
|
||||
|
||||
/**
|
||||
* 新增或编辑报告
|
||||
* @param vo
|
||||
@@ -99,7 +98,9 @@ public class ReportManageConroller {
|
||||
if (count>0){
|
||||
return Result.error("报告名称已存在");
|
||||
}
|
||||
String name = reportService.insert(entity, vo.getLabelList());
|
||||
String name = reportService.insert(entity, vo.getLabelList(),
|
||||
vo.getReportPreviewUserIdList(),
|
||||
vo.getReportPreviewAndDownloadUserIdList());
|
||||
map.put("reportName", name);
|
||||
return Result.success(map);
|
||||
}
|
||||
@@ -367,6 +368,40 @@ public class ReportManageConroller {
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 下载文件
|
||||
// * @param response
|
||||
// * @param fileId
|
||||
// * @throws IOException
|
||||
// */
|
||||
// @ApiOperation(value = "|下载文件")
|
||||
// @GetMapping("/download")
|
||||
// public void downloadPic(HttpServletResponse response, String fileId) throws IOException {
|
||||
//
|
||||
// try {
|
||||
// FileEntity entity = fileService.getFile(fileId);
|
||||
// String fileName = entity.getFileName();
|
||||
// String filename = URLEncoder.encode(fileName, "UTF-8");
|
||||
// response.setHeader("Content-Disposition", "attachment;filename=" + filename);
|
||||
// response.setContentType("application/x-download");
|
||||
//// File file = new File(uploadFile, entity.getSavePath());
|
||||
// // 上传方式:阿里云:alioss 华为云:hwobs
|
||||
// if ("hwobs".equals(uploadType)){
|
||||
// obsBootUtil.downFile(entity.getSavePath(), response);
|
||||
// }else if ("alioss".equals(uploadType)){
|
||||
// ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response);
|
||||
// }else if ("local".equals(uploadType)){
|
||||
// localFileUtil.downFile(entity.getSavePath(), response);
|
||||
// }
|
||||
// if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
||||
// String text = "text";
|
||||
// PdfUtil.addWatermarkToPdf(response, text);
|
||||
// }
|
||||
// } catch (Exception ex) {
|
||||
// log.info(ex.getMessage(),ex);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
* @param response
|
||||
@@ -383,14 +418,31 @@ public class ReportManageConroller {
|
||||
String filename = URLEncoder.encode(fileName, "UTF-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
|
||||
response.setContentType("application/x-download");
|
||||
// File file = new File(uploadFile, entity.getSavePath());
|
||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||
if ("hwobs".equals(uploadType)){
|
||||
obsBootUtil.downFile(entity.getSavePath(), response);
|
||||
}else if ("alioss".equals(uploadType)){
|
||||
ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response);
|
||||
}else if ("local".equals(uploadType)){
|
||||
localFileUtil.downFile(entity.getSavePath(), response);
|
||||
|
||||
//PDF文件需要加水印
|
||||
if (FILE_EXTENSIONS_PDF.equalsIgnoreCase(FileUtil.getFileExtension(fileName))) {
|
||||
String path = uploadFile + entity.getSavePath();
|
||||
FileOutputStream outputStream = new FileOutputStream(path);
|
||||
// 上传方式:阿里云:alioss 华为云:hwobs
|
||||
if ("hwobs".equals(uploadType)) {
|
||||
obsBootUtil.getFileFromOBS(entity.getSavePath(), outputStream);
|
||||
} else if ("alioss".equals(uploadType)) {
|
||||
ossClientUtil.getFileFromOSS(entity.getSavePath(), outputStream);
|
||||
} else if ("local".equals(uploadType)) {
|
||||
localFileUtil.getFileFromLocal(entity.getSavePath(), outputStream);
|
||||
}
|
||||
//给文件添加水印
|
||||
waterMarkUtil.addWatermarkToPdf(new FileInputStream(path), response);
|
||||
|
||||
} else {
|
||||
// 上传方式:阿里云:alioss 华为云:hwobs 本地:local
|
||||
if ("hwobs".equals(uploadType)){
|
||||
obsBootUtil.downFile(entity.getSavePath(), response);
|
||||
}else if ("alioss".equals(uploadType)){
|
||||
ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response);
|
||||
}else if ("local".equals(uploadType)){
|
||||
localFileUtil.downFile(entity.getSavePath(), response);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
@@ -405,8 +457,6 @@ public class ReportManageConroller {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 权限审批流程 添加报告按钮 可添加的报告
|
||||
* @return
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -16,6 +17,7 @@ import java.util.Date;
|
||||
*/
|
||||
@Data
|
||||
@TableName("power_apply")
|
||||
@Accessors(chain = true)
|
||||
public class PowerApply {
|
||||
|
||||
/**
|
||||
@@ -85,4 +87,11 @@ public class PowerApply {
|
||||
*/
|
||||
@TableField("del_flag")
|
||||
private Integer delFlag;
|
||||
|
||||
/**
|
||||
* 权限来源 1 上传报告时添加的
|
||||
* 2 单独申请的权限
|
||||
*/
|
||||
@TableField("power_source")
|
||||
private Integer powerSource;
|
||||
}
|
||||
|
||||
@@ -42,5 +42,5 @@ public class ReportContentEntity implements Serializable {
|
||||
private String reportContent;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1213467213486L;
|
||||
}
|
||||
@@ -41,6 +41,6 @@ public class ReportLabelEntity implements Serializable {
|
||||
private String labelId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 121348721347890417L;
|
||||
|
||||
}
|
||||
@@ -59,6 +59,6 @@ public class TreeLabelEntity implements Serializable {
|
||||
private Double orderNum;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 11283747892134701L;
|
||||
|
||||
}
|
||||
@@ -5,10 +5,11 @@ import com.adc.da.report.eo.PowerApplyAct;
|
||||
import com.adc.da.report.vo.DeleteParamRequestVO;
|
||||
import com.adc.da.report.vo.PowerApplyPageVO;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IPowerApplyService {
|
||||
public interface IPowerApplyService extends IService<PowerApply> {
|
||||
|
||||
/**
|
||||
* @param powerApplyPageVO
|
||||
@@ -58,4 +59,11 @@ public interface IPowerApplyService {
|
||||
public void deleteById(DeleteParamRequestVO deleteParamVO);
|
||||
|
||||
void saveBatch(List<PowerApplyAct> powerApplyActs);
|
||||
|
||||
/**
|
||||
* 根据报告id删除权限
|
||||
*
|
||||
* @param reportId 报表id
|
||||
*/
|
||||
void deleteByReportId(String reportId);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ public interface IReportService {
|
||||
* @param labelList
|
||||
* @return 报告名称
|
||||
*/
|
||||
String insert(ReportEntity entity, List<String> labelList) throws IOException;
|
||||
String insert(ReportEntity entity, List<String> labelList,
|
||||
List<String> reportPreviewUserIdList,
|
||||
List<String> reportPreviewAndDownloadUserIdList) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除报告
|
||||
|
||||
+79
-27
@@ -7,24 +7,20 @@ import com.adc.da.report.dao.mysql.FileDao;
|
||||
import com.adc.da.report.dao.mysql.ReportDao;
|
||||
import com.adc.da.report.dao.mysql.ReportLabelDao;
|
||||
import com.adc.da.report.dao.mysql.ReportUserDao;
|
||||
import com.adc.da.report.eo.FileEntity;
|
||||
import com.adc.da.report.eo.ReportEntity;
|
||||
import com.adc.da.report.eo.ReportLabelEntity;
|
||||
import com.adc.da.report.eo.ReportUserEntity;
|
||||
import com.adc.da.report.service.IReportContentService;
|
||||
import com.adc.da.report.service.IReportLabelService;
|
||||
import com.adc.da.report.service.IReportService;
|
||||
import com.adc.da.report.service.ITreeLabelService;
|
||||
import com.adc.da.report.eo.*;
|
||||
import com.adc.da.report.service.*;
|
||||
import com.adc.da.report.util.*;
|
||||
import com.adc.da.report.vo.ReportQueryVo;
|
||||
import com.adc.da.report.vo.ReportVo;
|
||||
import com.adc.da.sys.dao.mysql.RoleEODao;
|
||||
import com.adc.da.sys.entity.RoleEO;
|
||||
import com.adc.da.util.utils.CollectionUtils;
|
||||
import com.adc.da.util.utils.FileUtil;
|
||||
import com.adc.da.util.utils.StringUtils;
|
||||
import com.adc.da.util.utils.UUID;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -98,6 +94,10 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
@Autowired
|
||||
private LocalFileUtil localFileUtil;
|
||||
|
||||
@Resource
|
||||
private IPowerApplyService iPowerApplyService;
|
||||
|
||||
|
||||
/**
|
||||
* 新增或编辑报告
|
||||
*
|
||||
@@ -107,9 +107,12 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String insert(ReportEntity entity, List<String> labelList) throws IOException {
|
||||
public String insert(ReportEntity entity, List<String> labelList,
|
||||
List<String> reportPreviewUserIdList,
|
||||
List<String> reportPreviewAndDownloadUserIdList) throws IOException {
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
if (StringUtils.isEmpty(entity.getId())) {
|
||||
entity.setId(UUID.randomUUID10());
|
||||
entity.setCreateDate(format.format(new Date()));
|
||||
@@ -118,13 +121,36 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
entity.setUpdateDate(format.format(new Date()));
|
||||
reportDao.insert(entity);
|
||||
|
||||
//插入用户关系表
|
||||
entity.getReportUserIdList().forEach(c -> {
|
||||
ReportUserEntity reportUserEntity = new ReportUserEntity();
|
||||
reportUserEntity.setReportId(entity.getId());
|
||||
reportUserEntity.setUserId(c);
|
||||
reportUserDao.insert(reportUserEntity);
|
||||
});
|
||||
//插入power_apply权限表
|
||||
if (CollectionUtils.isNotEmpty(reportPreviewUserIdList)) {
|
||||
reportPreviewUserIdList.forEach(userId -> {
|
||||
PowerApply powerApply = new PowerApply();
|
||||
powerApply.setId(UUID.randomUUID10())
|
||||
.setPower(1)
|
||||
.setReportId(entity.getId())
|
||||
.setUserId(userId)
|
||||
.setCreateDate(new Date())
|
||||
.setCreateUserId(UserUtils.getUserId())
|
||||
.setDelFlag(0)
|
||||
.setPowerSource(1);
|
||||
iPowerApplyService.save(powerApply);
|
||||
});
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(reportPreviewAndDownloadUserIdList)) {
|
||||
reportPreviewAndDownloadUserIdList.forEach(userId -> {
|
||||
PowerApply powerApply = new PowerApply();
|
||||
powerApply.setId(UUID.randomUUID10())
|
||||
.setPower(2)
|
||||
.setReportId(entity.getId())
|
||||
.setUserId(userId)
|
||||
.setCreateDate(new Date())
|
||||
.setCreateUserId(UserUtils.getUserId())
|
||||
.setDelFlag(0)
|
||||
.setPowerSource(1);
|
||||
iPowerApplyService.save(powerApply);
|
||||
});
|
||||
}
|
||||
|
||||
//插入报表标签关系表
|
||||
labelList.forEach((label) -> {
|
||||
@@ -133,7 +159,7 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
});
|
||||
|
||||
//插入报表内容表
|
||||
iReportContentService.insertReportContent(entity.getId() ,entity.getFileId());
|
||||
iReportContentService.insertReportContent(entity.getId(), entity.getFileId());
|
||||
|
||||
CommonUtils.threadPoolExecutor().execute(() -> {
|
||||
//生成html
|
||||
@@ -157,14 +183,6 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
reportUserDao.delete(new QueryWrapper<ReportUserEntity>()
|
||||
.eq("reportId", entity.getId()));
|
||||
|
||||
//插入用户关系表
|
||||
entity.getReportUserIdList().forEach(c -> {
|
||||
ReportUserEntity reportUserEntity = new ReportUserEntity();
|
||||
reportUserEntity.setReportId(entity.getId());
|
||||
reportUserEntity.setUserId(c);
|
||||
reportUserDao.insert(reportUserEntity);
|
||||
});
|
||||
|
||||
//修改报表标签关系表(先删后增)
|
||||
iReportLabelService.deleteReportLabelByReportId(new String[]{entity.getId()});
|
||||
|
||||
@@ -174,6 +192,42 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
reportLabelDao.insert(reportLabelEntity);
|
||||
});
|
||||
|
||||
//TODO 插入报表内容表(先删后增)
|
||||
|
||||
//删除power_apply表中的对应权限
|
||||
iPowerApplyService.deleteByReportId(entity.getId());
|
||||
|
||||
//插入power_apply权限表
|
||||
if (CollectionUtils.isNotEmpty(reportPreviewUserIdList)) {
|
||||
reportPreviewUserIdList.forEach(userId -> {
|
||||
PowerApply powerApply = new PowerApply();
|
||||
powerApply.setId(UUID.randomUUID10())
|
||||
.setPower(1)
|
||||
.setReportId(entity.getId())
|
||||
.setUserId(userId)
|
||||
.setUpdateDate(new Date())
|
||||
.setUpdateUserId(UserUtils.getUserId())
|
||||
.setDelFlag(0)
|
||||
.setPowerSource(1);
|
||||
iPowerApplyService.save(powerApply);
|
||||
});
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(reportPreviewAndDownloadUserIdList)) {
|
||||
reportPreviewAndDownloadUserIdList.forEach(userId -> {
|
||||
PowerApply powerApply = new PowerApply();
|
||||
powerApply.setId(UUID.randomUUID10())
|
||||
.setPower(2)
|
||||
.setReportId(entity.getId())
|
||||
.setUserId(userId)
|
||||
.setUpdateDate(new Date())
|
||||
.setUpdateUserId(UserUtils.getUserId())
|
||||
.setDelFlag(0)
|
||||
.setPowerSource(1);
|
||||
iPowerApplyService.save(powerApply);
|
||||
});
|
||||
}
|
||||
|
||||
CommonUtils.threadPoolExecutor().execute(() -> {
|
||||
String key = entity.getId() + "-" + entity.getFileId();
|
||||
Boolean hasKey = stringRedisTemplate.hasKey(key);
|
||||
@@ -375,7 +429,6 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
List<String> userIdList = reportUserDao.selectList(
|
||||
new QueryWrapper<ReportUserEntity>().eq("reportId", c.getId()))
|
||||
.stream().map(ReportUserEntity::getUserId).collect(Collectors.toList());
|
||||
c.setReportUserIdList(userIdList);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
@@ -448,7 +501,6 @@ public class IReportServiceImpl extends ServiceImpl<ReportDao, ReportEntity>
|
||||
List<String> userIdList = reportUserDao.selectList(
|
||||
new QueryWrapper<ReportUserEntity>().eq("reportId", c.getId()))
|
||||
.stream().map(ReportUserEntity::getUserId).collect(Collectors.toList());
|
||||
c.setReportUserIdList(userIdList);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
+9
-1
@@ -10,6 +10,7 @@ import com.adc.da.report.vo.DeleteParamRequestVO;
|
||||
import com.adc.da.report.vo.PowerApplyPageVO;
|
||||
import com.adc.da.util.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -124,5 +125,12 @@ public class IpowerApplyServiceImpl extends ServiceImpl<PowerApplyDao, PowerAppl
|
||||
powerApplyActDao.batchDel(ids);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteByReportId(String reportId){
|
||||
UpdateWrapper<PowerApply> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("report_id", reportId);
|
||||
PowerApply updatePowerApply = new PowerApply();
|
||||
updatePowerApply.setDelFlag(1);
|
||||
getBaseMapper().update(updatePowerApply, updateWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.adc.da.report.util;
|
||||
|
||||
|
||||
import com.adc.da.login.util.UserUtils;
|
||||
import com.adc.da.sys.constant.TsConfigKeyEnum;
|
||||
import com.adc.da.sys.entity.UserEO;
|
||||
import com.adc.da.sys.service.iservice.IConfigService;
|
||||
import com.adc.da.sys.service.iservice.IUserEoService;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
||||
import org.apache.pdfbox.pdmodel.font.PDType0Font;
|
||||
import org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState;
|
||||
import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
|
||||
import org.apache.pdfbox.util.Matrix;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.*;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 水印工具类
|
||||
* @author CaiHaohan
|
||||
*/
|
||||
@Component
|
||||
public class WaterMarkUtil {
|
||||
|
||||
@Resource
|
||||
private IUserEoService userEoService;
|
||||
|
||||
@Resource
|
||||
private IConfigService configService;
|
||||
|
||||
public String getWaterMarkConfig() {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
||||
String formattedDate = currentDate.format(formatter);
|
||||
|
||||
UserEO user = userEoService.getUserById(UserUtils.getUserId());
|
||||
String userName = user.getUsname();
|
||||
|
||||
String configValue = configService.findConfigValueByKey(TsConfigKeyEnum.WATERMARK_PREFIX.getValue());
|
||||
|
||||
return configValue + " " + userName + " " + formattedDate;
|
||||
}
|
||||
|
||||
public void addWatermarkToPdf(FileInputStream inputStream, HttpServletResponse response) throws IOException {
|
||||
String watermarkText = getWaterMarkConfig();
|
||||
// 加载PDF文档
|
||||
try (PDDocument document = PDDocument.load(inputStream)) {
|
||||
// 设置水印字体、字体大小、颜色和透明度
|
||||
ClassPathResource fontResource = new ClassPathResource("fonts/SourceHanSerif-VF.ttf");
|
||||
PDType0Font font = PDType0Font.load(document, fontResource.getInputStream());
|
||||
float fontSize = 13.0f;
|
||||
Color color = new Color(100, 100, 100, 0);
|
||||
PDExtendedGraphicsState graphicsState = new PDExtendedGraphicsState();
|
||||
graphicsState.setNonStrokingAlphaConstant(0.4f);
|
||||
graphicsState.setStrokingAlphaConstant(0.4f);
|
||||
|
||||
// 遍历每一页并添加水印
|
||||
for (PDPage page : document.getPages()) {
|
||||
// 获取页面尺寸以计算水印位置
|
||||
PDRectangle pageSize = page.getMediaBox();
|
||||
float xStep = pageSize.getWidth() / 4;
|
||||
float yStep = pageSize.getHeight() / 4;
|
||||
float rotationInRadians = (float) Math.toRadians(20);
|
||||
|
||||
for (float xPosition = pageSize.getLowerLeftX(); xPosition <= pageSize.getWidth(); xPosition += xStep) {
|
||||
for (float yPosition = pageSize.getLowerLeftY(); yPosition <= pageSize.getHeight(); yPosition += yStep) {
|
||||
// 创建内容流并设置图形状态参数
|
||||
try (PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, true)) {
|
||||
contentStream.setGraphicsStateParameters(graphicsState);
|
||||
contentStream.setFont(font, fontSize);
|
||||
contentStream.setNonStrokingColor(color);
|
||||
contentStream.beginText();
|
||||
contentStream.setRenderingMode(RenderingMode.FILL);
|
||||
// 设置水印文本的旋转和位置
|
||||
contentStream.setTextMatrix(Matrix.getRotateInstance(rotationInRadians, xPosition, yPosition));
|
||||
contentStream.showText(watermarkText);
|
||||
contentStream.endText();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将处理后的PDF写入HTTP响应
|
||||
try (OutputStream outputStream = response.getOutputStream()) {
|
||||
document.save(outputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,12 @@ public class ReportVo {
|
||||
/**
|
||||
* 报告用户id
|
||||
*/
|
||||
private List<String> reportUserIdList;
|
||||
private List<String> reportPreviewUserIdList;
|
||||
|
||||
/**
|
||||
* 报告用户id
|
||||
*/
|
||||
private List<String> reportPreviewAndDownloadUserIdList;
|
||||
|
||||
/**
|
||||
* 报告涉密等级
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user