|
|
|
@ -1,5 +1,9 @@ |
|
|
|
package com.zdxt.auth.project.system.notice.service; |
|
|
|
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@ -14,6 +18,7 @@ import com.zdxt.auth.dto.ZdxtFileBean; |
|
|
|
import com.zdxt.auth.feign.FileUploadApi; |
|
|
|
import com.zdxt.auth.feign.UserApi; |
|
|
|
import com.zdxt.auth.feign.ZdxtFileCommonApi; |
|
|
|
import com.zdxt.auth.framework.web.domain.AjaxResult; |
|
|
|
import com.zdxt.auth.project.system.dept.mapper.DeptMapper; |
|
|
|
import com.zdxt.auth.project.system.dept.service.IDeptService; |
|
|
|
import com.zdxt.common.annotation.DataScope; |
|
|
|
@ -22,8 +27,11 @@ import com.zdxt.common.zdxtFile.FilePreviewUtilBean; |
|
|
|
import com.zdxt.common.zdxtFile.ZdxtFileCommon; |
|
|
|
import com.zdxt.domain.auth.Dept; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument; |
|
|
|
import org.apache.pdfbox.rendering.PDFRenderer; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import com.zdxt.auth.common.utils.security.ShiroUtils; |
|
|
|
import com.zdxt.auth.common.utils.text.Convert; |
|
|
|
@ -31,6 +39,8 @@ import com.zdxt.auth.project.system.notice.mapper.NoticeMapper; |
|
|
|
import com.zdxt.auth.project.system.notice.domain.Notice; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
|
|
|
|
/** |
|
|
|
* 公告 服务层实现 |
|
|
|
* |
|
|
|
@ -55,6 +65,10 @@ public class NoticeServiceImpl implements INoticeService |
|
|
|
@Autowired |
|
|
|
private UserApi userApi; |
|
|
|
|
|
|
|
@Value("${ruoyi.profile}") |
|
|
|
private String filePath; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 查询公告信息 |
|
|
|
* |
|
|
|
@ -352,4 +366,44 @@ public class NoticeServiceImpl implements INoticeService |
|
|
|
public int removeFile(String key) { |
|
|
|
return zdxtFileCommonApi.deleteZdxtFileById(key); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public AjaxResult transPdf(Notice notice) { |
|
|
|
List<byte[]> pngs = new ArrayList<>(); |
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
System.out.println("地址。。。。 " + filePath+notice.getUrl()); |
|
|
|
// 将文件地址和文件名拼接成路径 注意:线上环境不能使用\\拼接
|
|
|
|
if (com.zdxt.common.util.StringUtils.isNotEmpty(notice.getUrl())){ |
|
|
|
String url = notice.getUrl(); |
|
|
|
int index = url.indexOf("upload"); // 找到"示例"的索引位置
|
|
|
|
if (index != -1) { |
|
|
|
url = url.substring(index + "upload".length()); |
|
|
|
} |
|
|
|
notice.setUrl(url); |
|
|
|
} |
|
|
|
System.out.println("测试地址。。。。 " + filePath+notice.getUrl()); |
|
|
|
File file = new File(filePath+notice.getUrl()); |
|
|
|
try { |
|
|
|
// 写入文件
|
|
|
|
PDDocument doc = PDDocument.load(file); |
|
|
|
PDFRenderer renderer = new PDFRenderer(doc); |
|
|
|
int pageCount = doc.getNumberOfPages(); |
|
|
|
for (int i = 0; i < pageCount; i++) { |
|
|
|
// dpi为144,越高越清晰,转换越慢
|
|
|
|
BufferedImage image = renderer.renderImageWithDPI(i, 50); // Windows native DPI
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
|
|
ImageIO.write(image, "png", baos); // 使用"png"或其他支持的格式,如"jpg"
|
|
|
|
byte[] imageInByte = baos.toByteArray(); // 将图像数据转换为字节数组
|
|
|
|
pngs.add(imageInByte); |
|
|
|
baos.close(); // 关闭流
|
|
|
|
// 将图片写出到该路径下
|
|
|
|
//ImageIO.write(image, type, new File(fileAddress + "\\" + filename + "_" + (i + 1) + "." + type));
|
|
|
|
} |
|
|
|
long endTime = System.currentTimeMillis(); |
|
|
|
System.out.println("共耗时:" + ((endTime - startTime) / 1000.0) + "秒"); //转化用时
|
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return AjaxResult.success(pngs); |
|
|
|
} |
|
|
|
} |
|
|
|
|