|
@@ -1,20 +1,30 @@
|
|
|
package com.ruoyi.iit.service.impl;
|
|
package com.ruoyi.iit.service.impl;
|
|
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-
|
|
|
|
|
import com.ruoyi.common.annotation.DataScope;
|
|
import com.ruoyi.common.annotation.DataScope;
|
|
|
|
|
+import com.ruoyi.common.constant.Constants;
|
|
|
|
|
+import com.ruoyi.common.utils.CommonAsyncManager;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
|
+import com.ruoyi.common.utils.LibreOfficeConvertUtil;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
|
|
+import com.ruoyi.iit.domain.IitFileImage;
|
|
|
|
|
+import com.ruoyi.iit.domain.IitFileInfo;
|
|
|
import com.ruoyi.iit.domain.IitMyselfFile;
|
|
import com.ruoyi.iit.domain.IitMyselfFile;
|
|
|
|
|
+import com.ruoyi.iit.mapper.IitFileImageMapper;
|
|
|
|
|
+import com.ruoyi.iit.mapper.IitFileInfoMapper;
|
|
|
import com.ruoyi.iit.mapper.IitMyselfFileMapper;
|
|
import com.ruoyi.iit.mapper.IitMyselfFileMapper;
|
|
|
|
|
+import com.ruoyi.iit.service.IIitFileInfoService;
|
|
|
|
|
+import org.jodconverter.office.OfficeManager;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.security.core.token.TokenService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.ruoyi.iit.mapper.IitFileInfoMapper;
|
|
|
|
|
-import com.ruoyi.iit.domain.IitFileInfo;
|
|
|
|
|
-import com.ruoyi.iit.service.IIitFileInfoService;
|
|
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 文件管理Service业务层处理
|
|
* 文件管理Service业务层处理
|
|
@@ -23,17 +33,22 @@ import com.ruoyi.iit.service.IIitFileInfoService;
|
|
|
* @date 2025-04-11
|
|
* @date 2025-04-11
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
-public class IitFileInfoServiceImpl implements IIitFileInfoService
|
|
|
|
|
-{
|
|
|
|
|
|
|
+public class IitFileInfoServiceImpl implements IIitFileInfoService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IitFileInfoMapper iitFileInfoMapper;
|
|
private IitFileInfoMapper iitFileInfoMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IitMyselfFileMapper iitMyselfFileMapper;
|
|
private IitMyselfFileMapper iitMyselfFileMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IitFileImageMapper iitFileImageMapper;
|
|
|
|
|
+
|
|
|
@Value("${ruoyi.profile}")
|
|
@Value("${ruoyi.profile}")
|
|
|
private String profile;
|
|
private String profile;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OfficeManager officeManager;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 查询文件管理
|
|
* 查询文件管理
|
|
@@ -68,6 +83,17 @@ public class IitFileInfoServiceImpl implements IIitFileInfoService
|
|
|
return iitFileInfoMapper.selectMyselfList(iitFileInfo);
|
|
return iitFileInfoMapper.selectMyselfList(iitFileInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<String> getFileImage(Long id) {
|
|
|
|
|
+ IitFileImage queryParam = new IitFileImage();
|
|
|
|
|
+ queryParam.setFileId(id);
|
|
|
|
|
+ List<IitFileImage> fileImageList = iitFileImageMapper.selectIitFileImageList(queryParam);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(fileImageList)) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ return fileImageList.stream().map(IitFileImage::getImageUrl).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 新增文件管理
|
|
* 新增文件管理
|
|
|
*
|
|
*
|
|
@@ -104,10 +130,51 @@ public class IitFileInfoServiceImpl implements IIitFileInfoService
|
|
|
iitMyselfFile.setUserId(SecurityUtils.getUserId());
|
|
iitMyselfFile.setUserId(SecurityUtils.getUserId());
|
|
|
iitMyselfFile.setCreateTime(DateUtils.getNowDate());
|
|
iitMyselfFile.setCreateTime(DateUtils.getNowDate());
|
|
|
iitMyselfFileMapper.insertIitMyselfFile(iitMyselfFile);
|
|
iitMyselfFileMapper.insertIitMyselfFile(iitMyselfFile);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 文件转换成图片 并保存数据库
|
|
|
|
|
+ CommonAsyncManager.me().execute(fileToImage(filePath, filePath + Constants.PDF, officeManager,
|
|
|
|
|
+ iitFileInfo, iitFileImageMapper));
|
|
|
|
|
+
|
|
|
return insertResult;
|
|
return insertResult;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 操作日志记录
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param sourceFile 源文件
|
|
|
|
|
+ * @param tarPdfFile 目标文件
|
|
|
|
|
+ * @return 任务task
|
|
|
|
|
+ */
|
|
|
|
|
+ public static TimerTask fileToImage(final String sourceFile, final String tarPdfFile, OfficeManager officeManage,
|
|
|
|
|
+ IitFileInfo iitFileInfo, IitFileImageMapper iitFileImageMapper) {
|
|
|
|
|
+ return new TimerTask() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String pdfFile = LibreOfficeConvertUtil.convertToPdf(sourceFile, tarPdfFile, officeManage);
|
|
|
|
|
+ long timeMillis = System.currentTimeMillis();
|
|
|
|
|
+ int pageSize = LibreOfficeConvertUtil.convertToImage(pdfFile, timeMillis);
|
|
|
|
|
+ String pdfFileName = pdfFile.substring(pdfFile.lastIndexOf("/") + 1);
|
|
|
|
|
+ Long fileId = iitFileInfo.getId();
|
|
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
|
|
+ for (int i = 0; i < pageSize; i++) {
|
|
|
|
|
+ IitFileImage iitFileImage = new IitFileImage();
|
|
|
|
|
+ // String filePath = pdfFile + "." + i + ".png";
|
|
|
|
|
+ String imgPath = pdfFile.replace(pdfFileName, String.valueOf(timeMillis)) + "." + i + ".png";
|
|
|
|
|
+ String fileUrl = imgPath.replace("/home/inspur/iit/uploadPath", "/profile");
|
|
|
|
|
+ iitFileImage.setFileId(fileId);
|
|
|
|
|
+ iitFileImage.setImageUrl(fileUrl);
|
|
|
|
|
+ iitFileImage.setCreateTime(nowDate);
|
|
|
|
|
+ iitFileImageMapper.insertIitFileImage(iitFileImage);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private Long getFileSize(String filePath) {
|
|
private Long getFileSize(String filePath) {
|
|
|
File file = new File(filePath);
|
|
File file = new File(filePath);
|
|
|
// 转换成KB
|
|
// 转换成KB
|