|
@@ -10,6 +10,7 @@ import com.qmth.teachcloud.common.enums.PageSizeEnum;
|
|
|
import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
|
import com.qmth.teachcloud.common.util.ConvertUtil;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -27,6 +28,7 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.StringJoiner;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -55,9 +57,15 @@ public class HtmlToJpgUtil {
|
|
|
* @param pageSizeEnum 转化pdf的纸张类型
|
|
|
*/
|
|
|
public List<BasicAttachment> convertHtmlToJpg(String cardTitle, String htmlContent, PageSizeEnum pageSizeEnum) throws Exception {
|
|
|
+ boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("");
|
|
|
+ if (!oss && Objects.nonNull(dictionaryConfig.fssPublicDomain()) && !StringUtils.isBlank(dictionaryConfig.fssPublicDomain().getConfig()) && !dictionaryConfig.fssPublicDomain().getConfig().startsWith(SystemConstant.START_PARENT)) {
|
|
|
+ stringJoiner.add(dictionaryConfig.fssPublicDomain().getConfig()).add(File.separator);
|
|
|
+ }
|
|
|
+ stringJoiner = SystemConstant.getDirName(stringJoiner, UploadFileEnum.IMAGE, true);
|
|
|
+
|
|
|
// 本地存储目录
|
|
|
- File file = SystemConstant.getFileTempVar(SystemConstant.TEMP_PREFIX);
|
|
|
- String rootPath = file.getParent();
|
|
|
+ String rootPath = stringJoiner.toString();
|
|
|
// html临时路径
|
|
|
String htmlPath = rootPath + File.separator + "html" + File.separator + cardTitle + SystemConstant.HTML_PREFIX;
|
|
|
// pdf临时路径
|
|
@@ -68,6 +76,9 @@ public class HtmlToJpgUtil {
|
|
|
// html
|
|
|
try {
|
|
|
File htmlFile = new File(htmlPath);
|
|
|
+ if(!htmlFile.exists()){
|
|
|
+ htmlFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
// 生成html文件
|
|
|
FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), htmlFile);
|
|
|
// 转pdf文件
|
|
@@ -85,9 +96,6 @@ public class HtmlToJpgUtil {
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
} finally {
|
|
|
- if (Objects.nonNull(file)) {
|
|
|
- file.delete();
|
|
|
- }
|
|
|
ConvertUtil.delFolder(rootPath);
|
|
|
}
|
|
|
return basicAttachmentList;
|