恢复下载时添加水印接口
This commit is contained in:
@@ -37,6 +37,12 @@
|
||||
<artifactId>UserAgentUtils</artifactId>
|
||||
<version>1.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
<artifactId>itextpdf</artifactId>
|
||||
<version>5.5.13</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import com.itextpdf.text.BaseColor;
|
||||
import com.itextpdf.text.Element;
|
||||
import com.itextpdf.text.Rectangle;
|
||||
import com.itextpdf.text.pdf.*;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @Description:水印
|
||||
* @Author: super_liu
|
||||
@@ -15,7 +23,7 @@ public class WaterMarkUtil {
|
||||
*/
|
||||
public static boolean waterMark(String inputFile,
|
||||
String outputFile, String waterMarkName) {
|
||||
/* try {
|
||||
try {
|
||||
PdfReader reader = new PdfReader(inputFile);
|
||||
Field f = PdfReader.class.getDeclaredField("encrypted");
|
||||
f.setAccessible(true);
|
||||
@@ -65,8 +73,7 @@ public class WaterMarkUtil {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,6 +77,28 @@
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- pdf -->
|
||||
<dependency>
|
||||
<groupId>com.lowagie</groupId>
|
||||
<artifactId>itext</artifactId>
|
||||
<version>2.1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lowagie</groupId>
|
||||
<artifactId>itextasian</artifactId>
|
||||
<version>2.1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
<artifactId>itextpdf</artifactId>
|
||||
<version>5.5.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
<artifactId>itext-asian</artifactId>
|
||||
<version>5.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.adc.da.att.controller;
|
||||
|
||||
import com.adc.da.att.dao.UserDao;
|
||||
import com.adc.da.att.entity.AttFileEO;
|
||||
import com.adc.da.att.entity.TsUser;
|
||||
import com.adc.da.att.service.IAttFileEOService;
|
||||
import com.adc.da.att.vo.AttFileVo;
|
||||
import com.adc.da.file.store.IFileStore;
|
||||
import com.adc.da.http.ResponseMessage;
|
||||
import com.adc.da.http.Result;
|
||||
import com.adc.da.sys.entity.UserEO;
|
||||
import com.adc.da.util.MD5Util;
|
||||
import com.adc.da.util.UUIDUtils;
|
||||
import com.adc.da.util.WaterMarkUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
@@ -46,6 +50,9 @@ public class AttFileEOController {
|
||||
@Autowired
|
||||
private IFileStore iFileStore;
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
@Value("${file.path}")
|
||||
private String filePath;//文件存储路径
|
||||
|
||||
@@ -249,7 +256,7 @@ public class AttFileEOController {
|
||||
@ApiOperation(value = "|File|下载文件加水印")
|
||||
@GetMapping("/downloadFileForSarWaterMark")
|
||||
// @RequiresPermissions("sys:file:downloadFileForSar")
|
||||
public void downloadFileForSarWaterMark(String fileId, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||||
public void downloadFileForSarWaterMark(String userId,String fileId, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||||
AttFileEO attFileEO = attFileEOService.getFileInfo(fileId);
|
||||
InputStream is = null;
|
||||
OutputStream os = null;
|
||||
@@ -265,24 +272,23 @@ public class AttFileEOController {
|
||||
}
|
||||
String waterFilePath = newFilePath + attFileEO.getOldFileName();
|
||||
// 添加水印
|
||||
String waterContent = "";
|
||||
// String userId = LoginUserUtil.getUserId();
|
||||
// String userMsg = "";
|
||||
// UserEO userEO = userEOService.selectByPrimaryKey(userId);
|
||||
// if (userEO != null) {
|
||||
// userMsg = userEO.getUname() + ",";
|
||||
// if (StringUtils.isNotEmpty(userEO.getWorkNum())) {
|
||||
// userMsg += userEO.getWorkNum() + ",";
|
||||
// }
|
||||
// }
|
||||
String userMsg = "";
|
||||
TsUser tsUser = userDao.selectById(userId);
|
||||
if (tsUser != null) {
|
||||
userMsg = tsUser.getUname() + ",";
|
||||
if (StringUtils.isNotEmpty(tsUser.getWorkNum())) {
|
||||
userMsg += tsUser.getWorkNum() + ",";
|
||||
}
|
||||
}
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");//设置日期格式
|
||||
String date = df.format(new Date());
|
||||
// waterContent = userMsg + date;
|
||||
String waterContent = userMsg + date;
|
||||
//2020年9月5日 去掉水印处理
|
||||
// WaterMarkUtil.waterMark(oldFilePath,waterFilePath,waterContent);
|
||||
//2021年7月25日要求下载生成水印
|
||||
WaterMarkUtil.waterMark(oldFilePath,waterFilePath,waterContent);
|
||||
response.setHeader("Content-Disposition", "attachment;filename=\""+fileOldName+"\"");
|
||||
response.setContentType("application/octet-stream");
|
||||
File file = new File(filePath+attFileEO.getFilePath()+attFileEO.getFileName());
|
||||
File file = new File(waterFilePath);
|
||||
is = new FileInputStream(file);
|
||||
os = response.getOutputStream();
|
||||
IOUtils.copy(is, os);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.adc.da.att.dao;
|
||||
|
||||
import com.adc.da.att.entity.TsUser;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
public interface UserDao extends BaseMapper<TsUser> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.adc.da.att.entity;
|
||||
|
||||
import com.adc.da.base.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TsUser extends BaseEntity implements Serializable {
|
||||
@TableId
|
||||
private String usid;
|
||||
@TableField
|
||||
private String uname;
|
||||
@TableField
|
||||
private String workNum;
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user